diff --git a/ui/sign-in/src/experience-api.ts b/ui/sign-in/src/experience-api.ts index 497a05c..137514f 100644 --- a/ui/sign-in/src/experience-api.ts +++ b/ui/sign-in/src/experience-api.ts @@ -273,3 +273,28 @@ export async function submitMfa(verificationId: string): Promise { await identifyUser(verificationId); return submitInteraction(); } + +// --- WebAuthn MFA Verification --- + +export async function startWebAuthnAuth(): Promise> { + const res = await request('POST', '/verification/web-authn/authentication'); + if (!res.ok) { + const err = await res.json().catch(() => ({})); + throw new Error(err.message || `Failed to start passkey authentication (${res.status})`); + } + const data = await res.json(); + return data; +} + +export async function verifyWebAuthnAuth(payload: Record): Promise { + const res = await request('POST', '/verification/web-authn/authentication/verify', payload); + if (!res.ok) { + const err = await res.json().catch(() => ({})); + if (res.status === 422) { + throw new Error('Passkey verification failed. Please try again.'); + } + throw new Error(err.message || `Passkey verification failed (${res.status})`); + } + const data = await res.json(); + return data.verificationId; +}