1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

тестd32123322в

This commit is contained in:
MoonTestUse1
2025-01-05 01:00:04 +06:00
parent 540e3e69db
commit 7399092e69
4 changed files with 14 additions and 9 deletions

View File

@@ -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'

View File

@@ -24,7 +24,8 @@ export default defineConfig({
proxy: {
'/api': {
target: 'http://backend:8000',
changeOrigin: true
changeOrigin: true,
secure: false
}
}
}