再次优化了登陆注册界面与跳转逻辑

This commit is contained in:
yml
2026-05-22 23:52:15 +08:00
parent b68411166d
commit 94edda9710
6 changed files with 473 additions and 593 deletions
+34
View File
@@ -14,3 +14,37 @@ apiClient.interceptors.request.use((config) => {
}
return config
})
apiClient.interceptors.response.use(
(response) => response,
(error) => {
if (error?.response?.status !== 401) {
return Promise.reject(error)
}
const requestUrl = error.config?.url || ''
const isAdminRequest = requestUrl.startsWith('/admin')
const currentPath = window.location.pathname + window.location.search
if (isAdminRequest) {
localStorage.removeItem('admin_access_token')
localStorage.removeItem('admin_refresh_token')
if (!window.location.pathname.startsWith('/admin/login')) {
window.location.assign('/admin/login')
}
return Promise.reject(error)
}
localStorage.removeItem('access_token')
localStorage.removeItem('refresh_token')
localStorage.removeItem('user_id')
if (!window.location.pathname.startsWith('/m/login') && !window.location.pathname.startsWith('/m/register')) {
const redirect = encodeURIComponent(currentPath)
const loginPath = window.location.pathname.startsWith('/m') ? '/m/login' : '/login'
window.location.assign(`${loginPath}?redirect=${redirect}`)
}
return Promise.reject(error)
},
)