/** * A cancelled WebAuthn ceremony arrives as a failure, and the passkey plugin passes * better-auth's own codes through. These turn both into a sentence a writer can * act on. */ export type PasskeyFailure = { code?: string; message?: string } | null | undefined; export function addPasskeyMessage(error: PasskeyFailure): string { if (error?.code === 'SESSION_NOT_FRESH') { return 'For security, sign out and back in before adding a passkey.'; } if (error?.code === 'PREVIOUSLY_REGISTERED') { return 'That passkey is already on this account.'; } if (error?.code === 'REGISTRATION_CANCELLED') { return 'Passkey setup was cancelled.'; } return 'Could not add the passkey. Try again.'; } export function signInPasskeyMessage(error: PasskeyFailure): string { if (error?.code === 'BANNED_USER') { return 'This account is disabled. Ask whoever runs this instance.'; } if (error?.code === 'AUTH_CANCELLED') { return 'Passkey sign-in was cancelled.'; } return 'That passkey did not work. Try your password, or choose another passkey.'; }