Skip to content

Commit fe9e7dd

Browse files
committed
th-294: * make it so the token stays in the localstorage while the server is not accessible
1 parent 6a77056 commit fe9e7dd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

frontend/src/slices/auth/actions.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createAsyncThunk } from '@reduxjs/toolkit';
22

33
import { type AuthMode } from '~/libs/enums/enums.js';
44
import { getErrorMessage } from '~/libs/helpers/helpers.js';
5-
import { type HttpError } from '~/libs/packages/http/http.js';
5+
import { type HttpError, HttpCode } from '~/libs/packages/http/http.js';
66
import { StorageKey } from '~/libs/packages/storage/storage.js';
77
import { type AsyncThunkConfig, type ValueOf } from '~/libs/types/types.js';
88
import {
@@ -71,7 +71,12 @@ const getCurrent = createAsyncThunk<
7171
return await authApi.getCurrentUser();
7272
} catch (error) {
7373
notification.warning(getErrorMessage(error));
74-
await localStorage.drop(StorageKey.TOKEN);
74+
75+
const httpError = error as HttpError;
76+
77+
if (httpError.status === HttpCode.UNAUTHORIZED) {
78+
await localStorage.drop(StorageKey.TOKEN);
79+
}
7580
throw error;
7681
}
7782
});

0 commit comments

Comments
 (0)