import { api } from "./api"; export type User = { id: string; email: string; display_name: string | null; email_verified: boolean; }; export type Settings = { locale: string; currency: string; theme: string; notify_email: boolean; }; type Me = { user: User; settings: Settings }; class AuthStore { user = $state(null); settings = $state(null); loaded = $state(false); async refresh() { try { const me = await api.get("/auth/me"); this.user = me.user; this.settings = me.settings; } catch { this.user = null; this.settings = null; } finally { this.loaded = true; } } set(me: Me) { this.user = me.user; this.settings = me.settings; this.loaded = true; } async logout() { try { await api.post("/auth/logout"); } finally { this.user = null; this.settings = null; } } } export const auth = new AuthStore();