fix(client): migrate digital storage keys

This commit is contained in:
baiyanyun
2026-06-07 18:21:24 +08:00
parent fa5522e32e
commit 09d65701a3
11 changed files with 64 additions and 46 deletions

View File

@@ -111,7 +111,7 @@ export async function apiFetch<T = unknown>(
if (response.status === 401) {
clearToken();
window.dispatchEvent(new Event('zeroclaw-unauthorized'));
window.dispatchEvent(new Event('qimingclaw-digital-unauthorized'));
throw new UnauthorizedError();
}

View File

@@ -1,11 +1,12 @@
const TOKEN_KEY = 'zeroclaw_token';
const TOKEN_KEY = 'qimingclaw_digital_token';
const LEGACY_TOKEN_KEY = 'zeroclaw_token';
/**
* Retrieve the stored authentication token.
*/
export function getToken(): string | null {
try {
return localStorage.getItem(TOKEN_KEY);
return localStorage.getItem(TOKEN_KEY) ?? localStorage.getItem(LEGACY_TOKEN_KEY);
} catch {
return null;
}
@@ -17,6 +18,7 @@ export function getToken(): string | null {
export function setToken(token: string): void {
try {
localStorage.setItem(TOKEN_KEY, token);
localStorage.removeItem(LEGACY_TOKEN_KEY);
} catch {
// localStorage may be unavailable (e.g. in some private browsing modes)
}
@@ -28,6 +30,7 @@ export function setToken(token: string): void {
export function clearToken(): void {
try {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(LEGACY_TOKEN_KEY);
} catch {
// Ignore
}

View File

@@ -1,6 +1,5 @@
declare global {
interface Window {
__SGROBOT_BASE__?: string;
__QIMINGCLAW_DIGITAL_API_BASE__?: string;
}
}