Build [v.1.3.6]
This commit is contained in:
@@ -21,18 +21,15 @@ export const getBackendUrl = () => {
|
||||
* [C-01] Axios instance cu JWT Bearer token în header
|
||||
* și interceptor pentru 401 Unauthorized (token expired)
|
||||
*/
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: getBackendUrl()
|
||||
});
|
||||
const axiosInstance = axios.create({});
|
||||
|
||||
axiosInstance.interceptors.request.use((config) => {
|
||||
if (!config.baseURL) {
|
||||
config.baseURL = getBackendUrl(); // called at request time — always correct
|
||||
}
|
||||
const token = getToken();
|
||||
console.log('[API] Request interceptor - token exists:', !!token, 'URL:', config.url);
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
console.log('[API] Authorization header set');
|
||||
} else {
|
||||
console.warn('[API] No token found in localStorage');
|
||||
}
|
||||
return config;
|
||||
}, (error) => Promise.reject(error));
|
||||
@@ -43,7 +40,7 @@ axiosInstance.interceptors.response.use(
|
||||
// [L-01] Handle 401 Unauthorized — token expired
|
||||
if (error.response?.status === 401) {
|
||||
clearAuth();
|
||||
if (typeof window !== 'undefined') {
|
||||
if (typeof window !== 'undefined' && !window.location.pathname.includes('/login')) {
|
||||
window.location.href = '/login';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user