This commit is contained in:
Your Name
2026-07-23 17:56:25 +08:00
parent a05dae8412
commit 4970d8f8d3
4262 changed files with 735221 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import axios from 'axios'
const api = axios.create({
baseURL: import.meta.env.VITE_API_BASE || '/api',
timeout: 30000
})
api.interceptors.request.use((config) => {
const token = localStorage.getItem('kefu_token')
if (token) {
config.headers.Authorization = `Bearer ${token}`
}
return config
})
api.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
localStorage.removeItem('kefu_token')
localStorage.removeItem('kefu_user')
if (!window.location.hash.includes('/login')) {
window.location.hash = '#/login'
}
}
return Promise.reject(error)
}
)
export default api