bug fixes
This commit is contained in:
@@ -3,9 +3,17 @@ import { API_URL } from '../utils/config';
|
||||
import { getToken, removeToken, removeUser } from '../utils/storage';
|
||||
|
||||
let authInitialized = false;
|
||||
let isRedirectingToLogin = false;
|
||||
|
||||
export function setAuthInitialized(value: boolean): void {
|
||||
authInitialized = value;
|
||||
if (value === true) {
|
||||
isRedirectingToLogin = false;
|
||||
}
|
||||
}
|
||||
|
||||
export function resetRedirectFlag(): void {
|
||||
isRedirectingToLogin = false;
|
||||
}
|
||||
|
||||
export interface ApiError {
|
||||
@@ -46,7 +54,8 @@ class ApiService {
|
||||
(response) => response,
|
||||
async (error: AxiosError) => {
|
||||
if (error.response?.status === 401) {
|
||||
if (authInitialized) {
|
||||
if (authInitialized && !isRedirectingToLogin) {
|
||||
isRedirectingToLogin = true;
|
||||
// Clear tokens and redirect to login
|
||||
console.warn('Unauthorized request, redirecting to login');
|
||||
removeToken();
|
||||
|
||||
Reference in New Issue
Block a user