/** * Shared auth client instance for ChronoMind web. * * Uses @bytelyst/auth-client to eliminate hand-rolled auth API calls. * All auth operations (login, register, forgot password, etc.) go through this client. * Lazy-initialized to avoid localStorage access at module load time (test compat). */ import { createAuthClient, type AuthClient } from '@bytelyst/auth-client'; export const PRODUCT_ID = 'chronomind'; export function getBaseUrl(): string { if (typeof window !== 'undefined' && (window as unknown as Record).__PLATFORM_URL__) { return (window as unknown as Record).__PLATFORM_URL__ as string; } return process.env.NEXT_PUBLIC_PLATFORM_SERVICE_URL ?? 'https://api.chronomind.app'; } let _authClient: AuthClient | null = null; export function getAuthClient(): AuthClient { if (!_authClient) { _authClient = createAuthClient({ baseUrl: getBaseUrl(), productId: PRODUCT_ID, storagePrefix: 'chronomind', }); } return _authClient; }