getToken (lib/auth.ts)

mobileclaw · web/src/lib/auth.ts · typescript · Apache-2.0
auth

Simple localStorage token helper for authentication.

// Source: https://github.com/Good-karma-lab/mobileclaw | License: Apache-2.0 | Copyright 2025 ZeroClaw Labs
// Provided via justclaw.it.com; keep this notice with the code.
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
  }


... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key