Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

th-294: If the server is unavailable, the user is logged out of the system #307

Open
wants to merge 7 commits into
base: development
Choose a base branch
from
9 changes: 7 additions & 2 deletions frontend/src/slices/auth/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createAction, createAsyncThunk } from '@reduxjs/toolkit';

import { type AuthMode } from '~/libs/enums/enums.js';
import { getErrorMessage } from '~/libs/helpers/helpers.js';
import { type HttpError } from '~/libs/packages/http/http.js';
import { type HttpError, HttpCode } from '~/libs/packages/http/http.js';
import { ClientToServerEvent } from '~/libs/packages/socket/socket.js';
import { StorageKey } from '~/libs/packages/storage/storage.js';
import {
Expand Down Expand Up @@ -157,7 +157,12 @@ const getCurrent = createAsyncThunk<AuthUser, undefined, AsyncThunkConfig>(
return await authApi.getCurrentUser();
} catch (error) {
notification.warning(getErrorMessage(error));
await localStorage.drop(StorageKey.TOKEN);

const httpError = error as HttpError;

if (httpError.status === HttpCode.UNAUTHORIZED) {
await localStorage.drop(StorageKey.TOKEN);
}
throw error;
}
},
Expand Down