fix(F006): 未登录访问 /admin/ 时业务 code:401 自动跳登录页(不再白屏未授权)

This commit is contained in:
Sisyphus 2026-07-20 14:57:46 +08:00
parent e0534ee365
commit 9837d9fb41

View File

@ -41,9 +41,13 @@ http.interceptors.response.use(
const body = response.data as ApiEnvelope | undefined
if (body && typeof body === 'object' && 'code' in body) {
if (body.code === 0) return response
// 业务级 code:401 (如 /openapi/** 带 token 时 Spring Security 返未授权)
// 不清 token 不跳登录,只 reject 给调用方处理
// 真正的 token 过期走 error 拦截器 (HTTP status 401)
// 业务级 code:401
// 未登录(无 token)访问受保护接口(如 /sys/menu/nav)→ 跳登录页
// 已登录但权限不足(如 /openapi/** 带 token 被 Spring Security 拒)→ 保持 reject 给调用方
if (body.code === 401 && !localStorage.getItem(STORAGE_KEY)) {
handleAuthExpired()
return Promise.reject(body)
}
return Promise.reject(body)
}
return response