import { signal } from "@preact/signals"; interface AuthState { loading: boolean; authenticated: boolean; did: string | null; handle: string | null; } export const auth = signal({ loading: true, authenticated: false, did: null, handle: null, }); export async function checkSession() { try { const res = await fetch("/api/oauth/session"); const data = await res.json(); auth.value = { loading: false, authenticated: data.authenticated, did: data.did ?? null, handle: data.handle ?? null, }; } catch { auth.value = { loading: false, authenticated: false, did: null, handle: null }; } } export async function logout() { await fetch("/api/oauth/logout", { method: "POST" }); auth.value = { loading: false, authenticated: false, did: null, handle: null }; }