refactor(auth): enhance business login session validation and add tests
This commit is contained in:
@@ -10,6 +10,7 @@ import { fetchFacebookUserData } from "@/data/services";
|
||||
import { AuthStorage } from "@/data/storage/auth/auth_storage";
|
||||
import { UserStorage } from "@/data/storage/user/user_storage";
|
||||
import { deviceIdentifier, Logger, Result } from "@/utils";
|
||||
import { hasCompleteBusinessAuthSession } from "@/lib/auth/auth_session";
|
||||
|
||||
import { readGuestId } from "./auth-helpers";
|
||||
|
||||
@@ -235,7 +236,9 @@ export const guestLoginActor = fromPromise<LoginStatus, void>(async () => {
|
||||
// 1. deviceIdentifier.getDeviceId() —— 无则生成 + 落盘
|
||||
// (生产环境使用 fingerprintjs;非生产环境使用本地 UUID)
|
||||
// (给后续 OAuth/email 登录准备 deviceId,不在 splash 首次访问就 auto-create 游客)
|
||||
// 2. AuthStorage.getLoginToken() —— 有 → 读取 loginProvider,缺省回退 "email"
|
||||
// 2. AuthStorage loginToken + refreshToken
|
||||
// —— 两者都有 → 读取 loginProvider,缺省回退 "email"
|
||||
// —— 任一缺失 → 不算业务登录态
|
||||
// 3. AuthStorage.getFacebookId() —— 有 → facebookIdLogin → "facebook"
|
||||
// 4. AuthStorage.getGuestToken() —— 有 → "guest"
|
||||
// 5. 都没有 → "notLoggedIn"(让用户显式选 OAuth / Email / Guest 入口)
|
||||
@@ -245,9 +248,8 @@ export const checkAuthStatusActor = fromPromise<LoginStatus, void>(async () => {
|
||||
await deviceIdentifier.getDeviceId();
|
||||
const storage = AuthStorage.getInstance();
|
||||
|
||||
// 2. 查 loginToken
|
||||
const loginTokenR = await storage.getLoginToken();
|
||||
if (loginTokenR.success && loginTokenR.data) {
|
||||
// 2. 查业务登录 token:loginToken 和 refreshToken 必须同时存在。
|
||||
if (await hasCompleteBusinessAuthSession(storage)) {
|
||||
const providerR = await storage.getLoginProvider();
|
||||
if (providerR.success && isBusinessLoginProvider(providerR.data)) {
|
||||
return providerR.data;
|
||||
|
||||
Reference in New Issue
Block a user