Public Access
feat(auth): use the cookie session and refresh on 401
The token is no longer stored; a tbp_session flag remembers the login. apiFetch renews the session once on a 401 and sends the request again. Parallel requests and other tabs share one refresh, because Auth revokes the session when a refresh token is used twice. Only a 401 from the refresh ends the session; a 502 or no network shows the normal error.
This commit is contained in:
1 parent
5ff8d48c53
commit
d9a39dda22
34 files changed
+297
-147
No files matched your search
@@ -27,7 +27,7 @@ const renderPage = () => render(
|
||||
|
||||
describe('WishlistPage', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.setItem('tbp_jwt', 'token');
|
||||
localStorage.setItem('tbp_session', '1');
|
||||
globalThis.fetch = vi.fn(async () => ({ok: true, status: 200, json: async () => wishlist}));
|
||||
});
|
||||
|
||||
@@ -64,8 +64,8 @@ describe('WishlistPage', () => {
|
||||
expect(await screen.findByText('WISHLIST.EMPTY')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('opens the login page on a 401', async () => {
|
||||
fetch.mockResolvedValueOnce({ok: false, status: 401, json: async () => ({})});
|
||||
it('opens the login page on a 401 that the refresh cannot fix', async () => {
|
||||
fetch.mockResolvedValue({ok: false, status: 401, json: async () => ({})});
|
||||
renderPage();
|
||||
|
||||
await waitFor(() => expect(JSON.parse(screen.getByTestId('login').textContent).sessionExpired).toBe(true));
|
||||
|
||||
Reference in new issue
Block a user