Skip to main content

Handling errors

authenticate never rejects. A failure resolves with success: false, an error code and, usually, a warning:

const result = await LocalAuthentication.authenticate({ promptMessage: 'Unlock' })
if (!result.success) {
console.warn(result.error, result.warning)
}

warning is the platform's message, for logs only. Do not show it to users; it is not localized by the app and its wording can change between OS releases.

Grouping the codes​

Most apps need four branches, not fifteen:

import type { AuthenticationResult } from 'nitro-local-auth'

function outcome(result: AuthenticationResult) {
if (result.success) return 'unlocked'
switch (result.error) {
case 'user_cancel':
case 'system_cancel':
case 'app_cancel':
return 'dismissed' // Stay quiet.
case 'user_fallback':
return 'use-password' // iOS fallback button: show your own login.
case 'not_available':
case 'not_enrolled':
case 'passcode_not_set':
return 'unavailable' // Hide the biometric option.
default:
return 'failed' // lockout, authentication_failed, timeout, ...
}
}

The full list with platform sources is in Error codes.

Lockout​

After too many failed attempts, biometrics lock and the prompt resolves with lockout. The device passcode unlocks them. With the default device fallback, the next authenticate lets the user enter it; with disableDeviceFallback, tell the user to unlock the device first.

isLockedOut() reports the state. On Android the framework cannot be queried, so it reflects the latest prompt in this process: true after a prompt ended with lockout, false after a success.

Troubleshooting​

SymptomCause and fix
iOS: not_available with "Add NSFaceIDUsageDescription…"Info.plist lacks the Face ID usage description. See iOS setup.
Android: not_available with "Add <uses-permission …"The manifest lacks USE_BIOMETRIC, so the status methods also report no enrollment. See Android setup.
Android: not_available, "Biometric prompts need Android 10…"Android 8 or 9 with disableDeviceFallback. Keep the device fallback on, or hide biometric unlock on these versions.
passcode_not_setThe device has no passcode, PIN, pattern or password. On Android this includes the keyguard fallback when the device is not secure.
Simulator or emulator always failsNo biometrics or passcode are enrolled. Enroll them first (iOS: Features > Face ID > Enrolled).
An earlier call resolved with app_cancelA second authenticate call replaced it. Only one prompt runs at a time.
nitro-ui prepare complains about nitro-coreThe app resolves another nightly. Add the version overrides.