fix(auth): short-circuit guestLoginActor when local guestToken exists
Skip /auth/guest round-trip on splash Skip when localStorage already holds a valid guestToken. Avoids redundant API call (and the fingerprintjs deviceId probe) every time the user reopens splash. Trade-off: a server-revoked token still resolves "guest" until the first protected API call returns 401, which the HTTP layer handles. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -113,8 +113,21 @@ const syncFacebookBackendActor = fromPromise<
|
|||||||
// 由 splash UI 派发 `AuthGuestLoginSubmitted` 触发,**不**自动跑。
|
// 由 splash UI 派发 `AuthGuestLoginSubmitted` 触发,**不**自动跑。
|
||||||
// 取代了之前 checkAuthStatusActor 的 auto-guest-login 行为 —— 避免每次
|
// 取代了之前 checkAuthStatusActor 的 auto-guest-login 行为 —— 避免每次
|
||||||
// 访 splash 都自动创建游客账号污染后端。
|
// 访 splash 都自动创建游客账号污染后端。
|
||||||
|
//
|
||||||
|
// 短路优化:本地已有 guestToken 时直接 return "guest",跳过 deviceId
|
||||||
|
// 探测 + 后端 round-trip(splash 每打开一次就可能点一次 Skip,命中率高)。
|
||||||
|
// 已知 trade-off:若后端已吊销该 token,actor 仍返回 "guest" —— 任何后续
|
||||||
|
// 受保护 API 401 会由 HTTP 层清掉 token 回到 splash,无需在此处主动校验。
|
||||||
|
|
||||||
const guestLoginActor = fromPromise<LoginStatus, void>(async () => {
|
const guestLoginActor = fromPromise<LoginStatus, void>(async () => {
|
||||||
|
// 1. 先查本地 guestToken —— 已有就直接进 idle(带 pendingRedirect)
|
||||||
|
const hasTokenR = await AuthStorage.getInstance().hasGuestToken();
|
||||||
|
if (hasTokenR.success && hasTokenR.data) {
|
||||||
|
return "guest" as LoginStatus;
|
||||||
|
}
|
||||||
|
// Result.err(_) 时**不**抛 —— 落到 API 路径让真正的错误信号出现
|
||||||
|
|
||||||
|
// 2. 没有(或读不出)才走完整流程:拿 deviceId → 调后端
|
||||||
const deviceId = await deviceIdentifier.getDeviceId();
|
const deviceId = await deviceIdentifier.getDeviceId();
|
||||||
const result = await authRepository.guestLogin(deviceId);
|
const result = await authRepository.guestLogin(deviceId);
|
||||||
if (Result.isErr(result)) throw result.error;
|
if (Result.isErr(result)) throw result.error;
|
||||||
|
|||||||
Reference in New Issue
Block a user