This commit is contained in:
azizziy
2025-05-20 17:02:10 +05:00
commit c01e852a59
257 changed files with 27766 additions and 0 deletions

36
src/helpers/myAxios.ts Normal file
View File

@@ -0,0 +1,36 @@
import axios, { AxiosInstance, InternalAxiosRequestConfig, AxiosResponse } from 'axios';
import { BASE_URL } from '@/helpers/constants';
const myAxios: AxiosInstance = axios.create({
baseURL: BASE_URL,
timeout: 10000,
});
myAxios.interceptors.request.use(
(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig => {
const token = localStorage.getItem('token');
if (token) {
config.headers = config.headers || {};
config.headers['Authorization'] = `Bearer ${token}`;
}
return config;
},
error => {
return Promise.reject(error);
}
);
myAxios.interceptors.response.use(
(response: AxiosResponse) => {
return response.data;
},
error => {
// if (error.response?.status === 401) {
// localStorage.removeItem('token');
// window.location.href = '/';
// }
return Promise.reject(error);
}
);
export default myAxios;