chore: adjust file structure

This commit is contained in:
siujamo committed 2026-09-15 17:14:38 +08:00
1 parent 42e95594d2
commit 51df972bb5
2 files changed
+4 -4

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
import axios from "axios"
const axiosInstance = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL ?? "/api",
timeout: 10000,
headers: {
"Content-Type": "application/json",
},
})
axiosInstance.interceptors.request.use((config) => {
const token = localStorage.getItem("auth-token")
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
})
axiosInstance.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
localStorage.removeItem("auth-token")
window.location.href = "/login"
}
return Promise.reject(error)
}
)
export default axiosInstance