diff --git a/generator/frontend/src/lib/auth.ts b/generator/frontend/src/lib/auth.ts new file mode 100644 index 0000000..a9a8802 --- /dev/null +++ b/generator/frontend/src/lib/auth.ts @@ -0,0 +1,20 @@ +export type Me = { login: string | null; avatar_url?: string } + +export async function fetchMe(): Promise { + const r = await fetch('/api/auth/me', { credentials: 'include' }) + if (!r.ok) return { login: null } + return r.json() as Promise +} + +export function signInUrl(next?: string): string { + const n = next ?? (window.location.pathname + window.location.search) + return `/api/auth/github/login?next=${encodeURIComponent(n)}` +} + +export async function signOut(): Promise { + await fetch('/api/auth/logout', { + method: 'POST', + credentials: 'include', + headers: { 'Content-Type': 'application/json' }, + }) +}