Skip to main content

Checking availability

Five synchronous status methods describe what the device can do. They are cheap, so call them when you render the option rather than caching the result.

QuestionCallNotes
Is there a biometric sensor?hasHardware()true even when nothing is enrolled.
Can the user authenticate with biometrics?isEnrolled()On Android it checks Class 2 (weak) biometrics.
Which sensors exist?getSupportedAuthenticationTypes()Empty without biometric hardware. Enrolled or not.
What is the strongest enrolled method?getEnrolledLevel()Includes secret for a passcode without biometrics.
Are biometrics locked after failed attempts?isLockedOut()On Android, only the latest prompt's lockout in this process.

Choosing what to show​

import { LocalAuthentication } from 'nitro-local-auth'

function unlockLabel(): string | null {
const level = LocalAuthentication.getEnrolledLevel()
if (level === 'none') return null // Nothing to authenticate with.
if (level === 'secret') return 'Unlock with passcode'
const types = LocalAuthentication.getSupportedAuthenticationTypes()
if (types.includes('facial_recognition')) return 'Unlock with face'
if (types.includes('fingerprint')) return 'Unlock with fingerprint'
return 'Unlock'
}

getEnrolledLevel answers the passcode question too: secret means the device has a passcode, PIN, pattern or password but no biometrics, so authenticate with the default device fallback still works.

Refreshing on foreground​

The user can enroll or remove biometrics in Settings while the app is in the background. Read the status again when the app returns to the foreground, and after each authenticate call, which can change isLockedOut.

Platform details​

MethodiOSAndroid
hasHardwareLAContext reports a biometry type, or can evaluate biometrics.BiometricManager does not report missing or unavailable hardware. On Android 8 and 9, or without USE_BIOMETRIC, any supported type counts.
isEnrolledBiometrics can be evaluated, or are locked out (a lockout keeps enrollment).BiometricManager succeeds for Class 2. Always false on Android 8 and 9, and without USE_BIOMETRIC.
getSupportedAuthenticationTypesThe single biometry type: Touch ID, Face ID or Optic ID (iOS 17+).fingerprint from the system feature on all versions; facial_recognition and iris on Android 10 and later.
getEnrolledLevelbiometric_strong for any enrolled biometry.biometric_strong for Class 3 (Android 11+), biometric_weak for Class 2, then secret if the device is secure.
isLockedOutQueried from LAContext.The framework cannot be queried; reports whether the latest prompt in this process ended in a lockout.