Commit 90aefc7d by luoqi

fix(auth): 公开端点(auth:false)失败不再清会话,修复嵌入首屏「登录已过期」

api-client 清 session 分支未按 auth 门控,导致一次性 code 被重放/过期(10102)时
误清刚建立的会话。宿主 iframe 首屏用同一 code 换两次时,第二次 10102 把第一次
存好的有效会话清空 → SessionExpired。改为仅「带 token 的受保护请求」失败才清;
公开端点失败交由 bootstrap / doRefresh 各自按语义决定,兜底 fall-through 生效。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
parent 23e18d92
Pipeline #3345 failed in 0 seconds
...@@ -99,8 +99,18 @@ async function request<T>(path: string, opts: RequestOptions = {}): Promise<T> { ...@@ -99,8 +99,18 @@ async function request<T>(path: string, opts: RequestOptions = {}): Promise<T> {
} }
// ── 决定要不要清 session ── // ── 决定要不要清 session ──
// 保留 10107(权限不足):session 还有效,只是这条权限不够,不要把人踹下线 // 只有"带 token 的受保护请求(auth)"失败才可能意味着会话真的废了。
if (payload.code >= 10100 && payload.code < 10200 && payload.code !== ApiCode.AUTH_PERMISSION_DENIED) { // auth:false 的公开端点(exchange-code / refresh / mock-*)失败不代表现有会话失效 —
// 尤其一次性 code 被重放/过期(10102),绝不能把已建立的会话清掉
// (否则宿主 iframe 首屏用同一 code 换两次时,第二次的 10102 会误清刚建立的会话 → 「登录已过期」)。
// 这些公开端点的失败由各自调用方(bootstrap / doRefresh)按语义自行决定是否 clear。
// 保留 10107(权限不足):session 还有效,只是这条权限不够,不要把人踹下线。
if (
auth &&
payload.code >= 10100 &&
payload.code < 10200 &&
payload.code !== ApiCode.AUTH_PERMISSION_DENIED
) {
useAuthStore.getState().clear(); useAuthStore.getState().clear();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment