Spaces:
Sleeping
Sleeping
File size: 955 Bytes
fcea065 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /// <reference types="vite/client" />
import axios from "axios"
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || "http://localhost:7860"
console.log("Using API Base URL (Admin):", API_BASE_URL);
const adminClient = axios.create({
baseURL: API_BASE_URL,
headers: {
"Content-Type": "application/json",
},
})
adminClient.interceptors.request.use((config) => {
const admin_token = localStorage.getItem("admin_token")
if (admin_token) {
config.headers.Authorization = `Bearer ${admin_token}`
}
return config
})
adminClient.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401 && !error.config.url?.includes('/admin/auth/')) {
localStorage.removeItem("admin_token")
window.location.href = "/login"
}
return Promise.reject(error)
}
)
export default adminClient
|