Skip to content
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 { 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 { StorageKey } from '~/libs/packages/storage/storage.js';
import { type AsyncThunkConfig, type ValueOf } from '~/libs/types/types.js';
import {
Expand Down Expand Up @@ -71,7 +71,12 @@ const getCurrent = createAsyncThunk<
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