This commit is contained in:
Iliyan Angelov
2025-11-21 10:15:29 +02:00
parent 2251e97688
commit 722997bb19
22 changed files with 235 additions and 152 deletions

View File

@@ -1,4 +1,5 @@
import axios, { AxiosError, InternalAxiosRequestConfig } from 'axios';
import useAuthStore from '../../store/useAuthStore';
const rawBase = import.meta.env.VITE_API_URL || 'http://localhost:8000';
const normalized = String(rawBase).replace(/\/$/, '');
@@ -134,10 +135,21 @@ apiClient.interceptors.response.use(
localStorage.removeItem('token');
localStorage.removeItem('userInfo');
// Update auth store state
useAuthStore.getState().logout().catch(() => {
// Ignore logout errors, just clear the state
useAuthStore.setState({
token: null,
userInfo: null,
isAuthenticated: false,
isLoading: false,
});
});
if (!window.location.pathname.includes('/login')) {
window.location.href = '/login';
}
// Dispatch custom event to trigger login modal
window.dispatchEvent(new CustomEvent('auth:logout', {
detail: { message: 'Session expired. Please login again.' }
}));
const errorMessage = (error.response?.data as any)?.message || 'Session expired. Please login again.';
return Promise.reject({