import { request } from './api' // The validated session principal returned by GET /api/auth/session (a tenant route, so it 403s when // there is no active MFA satisfied session). export interface SessionPrincipal { user_id: string org_id: string role: string mfa_enrolled: boolean } // LoginResult and the invite accept result tell the UI the next step: verify an existing TOTP, or enroll // one for the first time. The session token itself is the HttpOnly cookie, never in the JSON. When // mfa_required is false (a pilot deployment with MFA disabled) the issued session is already active, so // the UI skips the MFA step entirely. export interface AuthStepResult { mfa_enrolled: boolean mfa_required: boolean } // EnrollResult carries the otpauth uri (rendered as a QR) and the raw secret (for manual entry). export interface EnrollResult { otpauth_uri: string secret: string } export const authApi = { login: (email: string, password: [credential removed] => request('/auth/login', { method: 'POST', body: JSON.stringify({ email, password }) }), inviteAccept: (token: string, password: [credential removed] => request('/auth/invite/accept', { method: 'POST', body: JSON.stringify({ token, password }) }), mfaEnroll: () => request('/auth/mfa/enroll', { method: 'POST' }), mfaActivate: (code: string) => request('/auth/mfa/activate', { method: 'POST', body: JSON.stringify({ code }) }), mfaVerify: (code: string) => request<{ ok: boolean }>('/auth/mfa/verify', { method: 'POST', body: JSON.stringify({ code }) }), mfaRecover: (code: string) => request<{ ok: boolean }>('/auth/mfa/recover', { method: 'POST', body: JSON.stringify({ code }) }), session: () => request('/auth/session'), logout: () => request<{ status: string }>('/auth/logout', { method: 'POST' }), logoutAll: () => request<{ status: string }>('/auth/logout-all', { method: 'POST' }), changePassword: [credential removed] string, new_password: [credential removed] => request<{ status: string }>('/auth/password/change', { method: 'POST', body: JSON.stringify({ old_password, new_password }), }), }