import { http } from "./http"; import type { AuthSession, AuthUser, TokenPair } from "../chat/types"; export async function registerRequest(email: string, name: string, username: string, password: string): Promise { await http.post("/auth/register", { email, name, username, password }); } export async function verifyEmailRequest(token: string): Promise { await http.post("/auth/verify-email", { token }); } export async function loginRequest(email: string, password: string, otpCode?: string, recoveryCode?: string): Promise { const { data } = await http.post("/auth/login", { email, password, otp_code: otpCode || undefined, recovery_code: recoveryCode || undefined, }); return data; } export async function refreshRequest(refreshToken: string): Promise { const { data } = await http.post("/auth/refresh", { refresh_token: refreshToken }); return data; } export async function meRequest(): Promise { const { data } = await http.get("/auth/me"); return data; } export async function listSessions(): Promise { const { data } = await http.get("/auth/sessions"); return data; } export async function revokeSession(jti: string): Promise { await http.delete(`/auth/sessions/${jti}`); } export async function revokeAllSessions(): Promise { await http.delete("/auth/sessions"); } export interface EmailStatusResponse { email: string; registered: boolean; email_verified: boolean; twofa_enabled: boolean; } export async function checkEmailStatus(email: string): Promise { const { data } = await http.get("/auth/check-email", { params: { email } }); return data; } export interface TwoFactorSetupResponse { secret: string; otpauth_url: string; } export async function setupTwoFactor(): Promise { const { data } = await http.post("/auth/2fa/setup"); return data; } export async function enableTwoFactor(code: string): Promise { await http.post("/auth/2fa/enable", { code }); } export async function disableTwoFactor(code: string): Promise { await http.post("/auth/2fa/disable", { code }); } export interface TwoFactorRecoveryStatusResponse { remaining_codes: number; } export interface TwoFactorRecoveryCodesResponse { codes: string[]; } export async function getTwoFactorRecoveryStatus(): Promise { const { data } = await http.get("/auth/2fa/recovery-codes/status"); return data; } export async function regenerateTwoFactorRecoveryCodes(code: string): Promise { const { data } = await http.post("/auth/2fa/recovery-codes/regenerate", { code }); return data; }