// Client-side helpers for the HF OAuth flow. The token is owned by // AuthProvider (src/context/auth-context.tsx); these read-only helpers exist // so non-React fetch utilities can attach `Authorization: Bearer ` // without going through React. const STORAGE_KEY = "lerobot-viz-oauth"; /** A token handed to a realm without a window (a Web Worker running the * batch pipeline); the main thread's token is read from localStorage. */ let tokenOverride: string | null = null; export function setAuthTokenOverride(token: string | null): void { tokenOverride = token; } export function getAuthToken(): string | null { if (typeof window === "undefined") return tokenOverride; try { const stored = window.localStorage.getItem(STORAGE_KEY); if (!stored) return null; const parsed = JSON.parse(stored) as { accessToken?: string }; return parsed.accessToken ?? null; } catch { return null; } } export function authHeaders(): Record { const token = getAuthToken(); return token ? { Authorization: `Bearer ${token}` } : {}; } export const AUTH_STORAGE_KEY = STORAGE_KEY; // Native