mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
тестd32123322в
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import axios, { InternalAxiosRequestConfig } from 'axios'
|
||||
import axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'
|
||||
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: '/api',
|
||||
@@ -10,22 +10,22 @@ const axiosInstance = axios.create({
|
||||
|
||||
// Добавляем перехватчик для добавления токена
|
||||
axiosInstance.interceptors.request.use(
|
||||
(config: InternalAxiosRequestConfig) => {
|
||||
(config: AxiosRequestConfig) => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) {
|
||||
if (token && config.headers) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => {
|
||||
(error: AxiosError) => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// Добавляем перехватчик для обработки ошибок
|
||||
axiosInstance.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
(response: AxiosResponse) => response,
|
||||
(error: AxiosError) => {
|
||||
if (error.response?.status === 401) {
|
||||
localStorage.removeItem('token')
|
||||
window.location.href = '/admin/login'
|
||||
|
@@ -24,7 +24,8 @@ export default defineConfig({
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://backend:8000',
|
||||
changeOrigin: true
|
||||
changeOrigin: true,
|
||||
secure: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user