import { browser } from "$app/environment"; const STORAGE_KEY = "bg.token"; function readToken(): string | null { if (!browser) { return null; } return localStorage.getItem(STORAGE_KEY); } function createAuth() { let token = $state(readToken()); return { get token() { return token; }, get isAuthenticated() { return token !== null && token.length > 0; }, login(value: string) { token = value; if (browser) { localStorage.setItem(STORAGE_KEY, value); } }, logout() { token = null; if (browser) { localStorage.removeItem(STORAGE_KEY); } }, }; } export const auth = createAuth();