passkeyErrorMessage function
Maps a ceremony / native-authenticator error to a user-facing message.
Implementation
String passkeyErrorMessage(Object error, {bool setup = false}) {
final action = setup ? 'setup' : 'sign-in';
if (error is PasskeyAuthCancelledException) {
return 'Passkey $action was cancelled.';
}
if (error is DomainNotAssociatedException) {
return 'Passkeys are not enabled for this app yet.';
}
if (error is NoCredentialsAvailableException) {
return setup ? 'Passkey $action failed.' : 'No passkey found for this account.';
}
if (error is DeviceNotSupportedException) {
return 'Passkeys are not supported on this device.';
}
if (error is ExcludeCredentialsCanNotBeRegisteredException) {
return 'You already have a passkey on this device.';
}
// Surface the native error code for anything unmapped (e.g. an unhandled
// iOS/Android authenticator error) so a failure is diagnosable on-screen.
if (error is PlatformException) {
return 'Passkey $action failed (${error.code}).';
}
return 'Passkey $action failed.';
}