Initial Mento CRM: portal OTP, reports, SMS, and deploy for crm.montzar.ir.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export const api = axios.create({
|
||||
baseURL: '/api',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const token =
|
||||
localStorage.getItem('mento_token') ?? localStorage.getItem('ment_token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
if (typeof FormData !== 'undefined' && config.data instanceof FormData) {
|
||||
if (config.headers && 'Content-Type' in config.headers) {
|
||||
delete config.headers['Content-Type'];
|
||||
}
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (axios.isAxiosError(error) && error.response?.status === 401) {
|
||||
const path = window.location.pathname;
|
||||
if (path.startsWith('/p/')) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
localStorage.removeItem('mento_token');
|
||||
localStorage.removeItem('mento_user');
|
||||
localStorage.removeItem('ment_token');
|
||||
localStorage.removeItem('ment_user');
|
||||
if (!path.startsWith('/login')) {
|
||||
const redirect = encodeURIComponent(path + window.location.search);
|
||||
window.location.assign(`/login?redirect=${redirect}`);
|
||||
}
|
||||
}
|
||||
return Promise.reject(error);
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user