fix(client): migrate digital storage keys
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
declare global {
|
||||
interface Window {
|
||||
__SGROBOT_BASE__?: string;
|
||||
__QIMINGCLAW_DIGITAL_API_BASE__?: string;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user