Fix jwt-token

This commit is contained in:
2025-08-18 05:47:56 +02:00
parent 4c67e49621
commit ea76efb3f1
3 changed files with 24 additions and 9 deletions

View File

@@ -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);
}