fix: manejar error 401 automaticamente y agregar migracion de columnas routes

This commit is contained in:
2026-02-25 19:49:29 -05:00
parent fd95df461b
commit dc827bcbf4
4 changed files with 83 additions and 4 deletions

View File

@ -31,6 +31,22 @@ client.interceptors.response.use(
(error) => {
if (error.response) {
console.error('API Error:', error.response.status, error.response.data)
// Si el token expiró o es inválido, limpiar sesión y redirigir al login
if (error.response.status === 401) {
const currentPath = window.location.pathname
// Solo redirigir si no estamos ya en la página de login
if (!currentPath.includes('/auth') && !currentPath.includes('/login')) {
localStorage.removeItem('auth_token')
localStorage.removeItem('user_role')
localStorage.removeItem('user_name')
localStorage.removeItem('profile_photo_url')
// Redirigir al login con mensaje
window.location.href = '/auth?reason=session_expired'
}
}
} else if (error.request) {
// La solicitud fue hecha pero no hubo respuesta (timeout, servidor dormido, etc.)
console.error('Network Error: No response from server', error.message)
}
return Promise.reject(error)
}