Write on the margins of the internet. Powered by the AT Protocol. margin.at
extension web atproto comments
at main 19 lines 501 B view raw
1import { atom } from "nanostores"; 2import { checkSession } from "../api/client"; 3import type { UserProfile } from "../types"; 4 5export const $user = atom<UserProfile | null>(null); 6export const $isLoading = atom<boolean>(true); 7 8export async function initAuth() { 9 $isLoading.set(true); 10 const session = await checkSession(); 11 $user.set(session); 12 $isLoading.set(false); 13} 14 15export function logout() { 16 fetch("/auth/logout", { method: "POST" }).then(() => { 17 window.location.href = "/"; 18 }); 19}