.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user