import { api, setTokens, clearTokens } from "@/lib/api"; export interface UserProfile { id: string; email: string; full_name: string | null; phone: string | null; role: "client" | "admin"; } interface AuthResponse { access_token: string; refresh_token: string; token_type: string; expires_in: number; } export async function login(email: string, password: string): Promise { const tokens = await api.post("/auth/login", { email, password }); setTokens(tokens.access_token, tokens.refresh_token); return api.get("/auth/me"); } export async function register( email: string, password: string, name: string ): Promise { const res = await api.post("/auth/register", { email, password, name }); if ("access_token" in res) { setTokens(res.access_token, (res as AuthResponse).refresh_token); return api.get("/auth/me"); } // Email confirmation required — no session yet return null; } export async function getMe(): Promise { return api.get("/auth/me"); } export async function updateProfile( full_name: string, phone: string | null ): Promise { return api.patch("/auth/me", { full_name, phone }); } export async function forgotPassword(email: string): Promise { await api.post("/auth/forgot-password", { email }); } export function logout() { clearTokens(); }