fix(auth): 退出授权清除匿名访客身份,登出后不再被自动重登

This commit is contained in:
z.zhang 2026-10-22 23:35:13 +08:00
parent 9e37d4a034
commit 43cb20eeb4
3 changed files with 13 additions and 2 deletions

View File

@ -50,6 +50,15 @@ function ensureVisitorId(): string {
} }
} }
export function resetVisitorId(): void {
memoryVisitorId = null;
try {
window.localStorage.removeItem(ANONYMOUS_VISITOR_KEY);
} catch {
// 隐私模式等场景下 localStorage 不可用,忽略即可
}
}
let desktopDeviceId: Promise<string> | null = null; let desktopDeviceId: Promise<string> | null = null;
async function getDesktopDeviceId(): Promise<string> { async function getDesktopDeviceId(): Promise<string> {

View File

@ -6,7 +6,7 @@ import {
SafetyCertificateOutlined, UserOutlined, WarningOutlined, SafetyCertificateOutlined, UserOutlined, WarningOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { clientFetch, getClientMode, type ClientMode } from '../api/client'; import { clientFetch, getClientMode, resetVisitorId, type ClientMode } from '../api/client';
export type AuthUser = { export type AuthUser = {
user_id: string; user_id: string;
@ -184,6 +184,7 @@ export function AuthProvider(props: { children: ReactNode }) {
await clientFetch('/api/auth/logout', { method: 'POST' }); await clientFetch('/api/auth/logout', { method: 'POST' });
} finally { } finally {
clearSensitiveBrowserState(); clearSensitiveBrowserState();
resetVisitorId();
await refresh(); await refresh();
} }
}, [refresh]); }, [refresh]);

View File

@ -73,7 +73,7 @@ from server.contracts import INTERFACE_VERSION, IntentResult # 跨层握手与
from server.state.checkpoints import get_checkpoints # 成对快照仓(时间线) from server.state.checkpoints import get_checkpoints # 成对快照仓(时间线)
from server.state.store import get_store # 世界状态单例 from server.state.store import get_store # 世界状态单例
from server.auth.context import get_identity from server.auth.context import get_identity
from server.auth.middleware import AuthenticationMiddleware from server.auth.middleware import ANONYMOUS_COOKIE, AuthenticationMiddleware
from server.auth.licenses import ( from server.auth.licenses import (
DESKTOP_COOKIE, DESKTOP_COOKIE,
WEB_LICENSE_COOKIE, WEB_LICENSE_COOKIE,
@ -1219,6 +1219,7 @@ def create_app() -> FastAPI:
response.delete_cookie("aps_session", path="/") response.delete_cookie("aps_session", path="/")
response.delete_cookie(DESKTOP_COOKIE, path="/") response.delete_cookie(DESKTOP_COOKIE, path="/")
response.delete_cookie(WEB_LICENSE_COOKIE, path="/") response.delete_cookie(WEB_LICENSE_COOKIE, path="/")
response.delete_cookie(ANONYMOUS_COOKIE, path="/")
return {"ok": True} return {"ok": True}
@app.get("/api/auth/users") @app.get("/api/auth/users")