updates
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user