Fix jwt-token
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const API_BASE_URL = process.env.NODE_ENV === 'production'
|
||||
? '/drones/api'
|
||||
: 'http://localhost:3001/api';
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL ||
|
||||
(process.env.NODE_ENV === 'production'
|
||||
? '/drones/api'
|
||||
: 'http://localhost:3002/api');
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
@@ -30,9 +31,12 @@ api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response?.status === 401) {
|
||||
// Token expired or invalid
|
||||
// Token expired or invalid - let AuthContext handle this
|
||||
localStorage.removeItem('token');
|
||||
window.location.href = '/login';
|
||||
// Only redirect if not already on login page
|
||||
if (window.location.pathname !== '/login') {
|
||||
window.location.href = '/login';
|
||||
}
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user