Files
qiming/qimingclaw/crates/agent-electron-client/embedded/sgrobot-digital/src/lib/auth.ts
2026-06-05 15:02:42 +08:00

43 lines
805 B
TypeScript

const TOKEN_KEY = 'zeroclaw_token';
/**
* Retrieve the stored authentication token.
*/
export function getToken(): string | null {
try {
return localStorage.getItem(TOKEN_KEY);
} catch {
return null;
}
}
/**
* Store an authentication token.
*/
export function setToken(token: string): void {
try {
localStorage.setItem(TOKEN_KEY, token);
} catch {
// localStorage may be unavailable (e.g. in some private browsing modes)
}
}
/**
* Remove the stored authentication token.
*/
export function clearToken(): void {
try {
localStorage.removeItem(TOKEN_KEY);
} catch {
// Ignore
}
}
/**
* Returns true if a token is currently stored.
*/
export function isAuthenticated(): boolean {
const token = getToken();
return token !== null && token.length > 0;
}