This commit is contained in:
2026-04-17 20:16:51 +02:00
parent c3c05e8af4
commit adb797e709
3 changed files with 47 additions and 39 deletions

View File

@@ -1,30 +1,18 @@
import axios from 'axios';
/*
const axiosInstance = axios.create({
baseURL: '/api',
headers: { 'Content-Type': 'application/json' },
});
*/
const axiosInstance = axios.create({
baseURL: 'https://api.testsite.deinedorfapp.de/api',
//baseURL: 'http://localhost:5173/api',
headers: { 'Content-Type': 'application/json' },
});
axiosInstance.interceptors.request.use((config) => {
const token = localStorage.getItem('jwt_token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
withCredentials: true
});
axiosInstance.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
localStorage.removeItem('jwt_token');
const isAuthCheck = error.config?.url?.includes('/auth/me');
const isLogin = error.config?.url?.includes('/auth/login');
if (error.response?.status === 401 && !isAuthCheck && !isLogin) {
window.location.href = '/login';
}
return Promise.reject(error);