export type User = { id: string username: string } async function request(path: string, options: RequestInit = {}): Promise { const response = await fetch(path, { ...options, credentials: 'include', headers: { 'Content-Type': 'application/json', ...options.headers, }, }) if (!response.ok) { const body = await response.json().catch(() => ({ detail: response.statusText })) throw new Error(body.detail ?? `Request failed: ${response.status}`) } if (response.status === 204) { return undefined as T } return response.json() as Promise } export function register(username: string, password: string): Promise { return request('/auth/register', { method: 'POST', body: JSON.stringify({ username, password }), }) } export function login(username: string, password: string): Promise { return request('/auth/login', { method: 'POST', body: JSON.stringify({ username, password }), }) } export function logout(): Promise { return request('/auth/logout', { method: 'POST' }) } export function me(): Promise { return request('/auth/me') }