fix(auth): return to guest session on logout
This commit is contained in:
@@ -1,19 +1,5 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* AuthStorage 完整实现(基于 unstorage 抽象)
|
||||
*
|
||||
* SECURITY: 当前与 Dart 端行为一致,refresh_token 以明文存于 localStorage。
|
||||
* 后续轮次将升级到 HttpOnly Cookie 方案,参见 `clearAuthData` 处的 TODO 标记。
|
||||
*
|
||||
* 设计说明:
|
||||
* - 内部使用 `SpAsyncUtil` 静态类(@/utils/storage)
|
||||
* - 浏览器 → `localStorage` driver;SSR → memory driver(unstorage 自动)
|
||||
* - 单例挂在 class 静态字段,规避 HMR 复用污染
|
||||
* - `hasXxx` = `token != null && token.length > 0`,对齐 Dart 端 `isNotEmpty` 语义
|
||||
* - `clearAuthData` 顺序清理:loginToken → loginProvider → guestToken → refreshToken,任一失败立即返回
|
||||
*/
|
||||
|
||||
import { LoginStatus, type LoginStatus as LoginStatusT } from "@/data/dto/auth";
|
||||
import { Result, type Result as ResultT, SpAsyncUtil } from "@/utils";
|
||||
import { StorageKeys } from "../storage_keys";
|
||||
@@ -117,6 +103,16 @@ export class AuthStorage implements IAuthStorage {
|
||||
|
||||
// ---- bulk clear ----
|
||||
|
||||
async clearBusinessAuthData(): Promise<ResultT<void>> {
|
||||
const r1 = await this.clearLoginToken();
|
||||
if (!r1.success) return r1;
|
||||
const r2 = await this.clearRefreshToken();
|
||||
if (!r2.success) return r2;
|
||||
const r3 = await this.clearFacebookId();
|
||||
if (!r3.success) return r3;
|
||||
return this.clearLoginProvider();
|
||||
}
|
||||
|
||||
async clearAuthData(): Promise<ResultT<void>> {
|
||||
const r1 = await this.clearLoginToken();
|
||||
if (!r1.success) return r1;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* 对齐 Dart 端 `IAuthStorage`(lib/data/services/storage/iauth_storage.dart):
|
||||
* - loginToken / loginProvider / guestToken / deviceId / refreshToken / facebookId 字段的 CRUD
|
||||
* - `clearAuthData()` 批量清空登录态
|
||||
* - `clearBusinessAuthData()` 仅清空真实用户登录态,保留 guest token / deviceId
|
||||
* - 所有方法返回 `Promise<Result<T>>`,与 Dart `Future<Result<T>>` 对齐
|
||||
*/
|
||||
|
||||
@@ -38,5 +39,6 @@ export interface IAuthStorage {
|
||||
setFacebookId(id: string): Promise<Result<void>>;
|
||||
clearFacebookId(): Promise<Result<void>>;
|
||||
|
||||
clearBusinessAuthData(): Promise<Result<void>>;
|
||||
clearAuthData(): Promise<Result<void>>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user