LocalAuthentication
import { LocalAuthentication } from 'nitro-local-auth'
A Nitro HybridObject with static methods only, implemented in Swift (HybridLocalAuthentication on LocalAuthentication) and Kotlin (HybridLocalAuthentication on BiometricPrompt). NitroUI runs JavaScript on the main thread, so every method runs there.
| Member | Returns | Summary |
|---|---|---|
hasHardware() | boolean | Biometric hardware exists, enrolled or not. |
isEnrolled() | boolean | Biometrics are enrolled. |
getSupportedAuthenticationTypes() | AuthenticationType[] | Biometric methods the device supports. |
getEnrolledLevel() | SecurityLevel | Strongest enrolled kind of authentication. |
isLockedOut() | boolean | Biometrics are locked after failed attempts. |
authenticate(options?) | Promise<AuthenticationResult> | Shows the system prompt. |
cancelAuthenticate() | void | Closes the open prompt. |
The status methods are synchronous and cheap. Call them again when the app returns to the foreground, since the user can change enrollment in Settings.
hasHardware
static hasHardware(): boolean
Returns whether the device has biometric hardware, whether or not biometrics are enrolled or locked.
isEnrolled
static isEnrolled(): boolean
Returns whether the user has enrolled biometrics they can authenticate with. On Android it checks Class 2 (weak) biometrics, and is always false on Android 8 and 9. On iOS a lockout does not remove the enrollment, so it stays true while locked out.
getSupportedAuthenticationTypes
static getSupportedAuthenticationTypes(): AuthenticationType[]
Returns the biometric methods the device supports, enrolled or not: AuthenticationType values. Empty when the device has no biometric hardware. iOS returns at most one type.
getEnrolledLevel
static getEnrolledLevel(): SecurityLevel
Returns the strongest kind of authentication the device has enrolled, as a SecurityLevel: none, secret (passcode only), biometric_weak or biometric_strong. iOS reports biometric_strong for any enrolled biometry; Android reports biometric_strong only for Class 3 on Android 11 and later.
isLockedOut
static isLockedOut(): boolean
Returns whether biometrics are locked after too many failed attempts. The device passcode unlocks them. Android cannot query this, so it reports the lockout of the latest prompt the app showed in this process: true after a prompt ended with lockout, false after a success.
authenticate
static authenticate(options?: AuthenticateOptions): Promise<AuthenticationResult>
Shows the system prompt and resolves when it closes, with an AuthenticationResult. It never rejects: a failure resolves with success: false and an AuthenticationError. Only one prompt runs at a time; a call while a prompt is open resolves the earlier one with app_cancel.
Options are described in AuthenticateOptions. On iOS, add NSFaceIDUsageDescription to the app's Info.plist before using Face ID; without it the call resolves with not_available.
const result = await LocalAuthentication.authenticate({
promptMessage: 'Unlock your account',
disableDeviceFallback: true,
})
cancelAuthenticate
static cancelAuthenticate(): void
Closes the open prompt, which then resolves with app_cancel. Does nothing when no prompt is open. On Android the keyguard confirm-credential screen cannot be closed; the promise resolves with app_cancel at once and the screen's result is ignored.