再次优化了登陆注册界面与跳转逻辑
This commit is contained in:
@@ -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)
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user