import { API_BASE, handleResponse } from './client'; export interface User { id: string; email: string; is_admin: boolean; } export interface RegisterRequest { email: string; password: string; } export interface LoginRequest { email: string; password: string; } export interface LoginResponse { // The session token is delivered via an HttpOnly cookie, not the JSON body. expires_at: string; user: User; } export interface RegisterResponse { id: string; email: string; created_at: string; } export const authApi = { async register(data: RegisterRequest): Promise { const response = await fetch(`${API_BASE}/auth/register`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify(data), }); return handleResponse(response); }, async login(data: LoginRequest): Promise { const response = await fetch(`${API_BASE}/auth/login`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify(data), }); return handleResponse(response); }, async logout(): Promise { await fetch(`${API_BASE}/auth/logout`, { method: 'POST', credentials: 'include', }); }, async getMe(): Promise { const response = await fetch(`${API_BASE}/users/me`, { credentials: 'include', }); return handleResponse(response); }, };