Skip to main content

Migrating from expo-local-authentication

The API follows expo-local-authentication, with three differences:

  1. Status methods are synchronous. Only authenticate returns a promise.
  2. Enums are string unions, such as 'facial_recognition' and 'biometric_strong', instead of numeric enums.
  3. Additions: isLockedOut and the optic_id authentication type.
-import * as LocalAuthentication from 'expo-local-authentication'
+import { LocalAuthentication } from 'nitro-local-auth'

-const hasHardware = await LocalAuthentication.hasHardwareAsync()
-const enrolled = await LocalAuthentication.isEnrolledAsync()
+const hasHardware = LocalAuthentication.hasHardware()
+const enrolled = LocalAuthentication.isEnrolled()

-const types = await LocalAuthentication.supportedAuthenticationTypesAsync()
-if (types.includes(LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION)) {
+const types = LocalAuthentication.getSupportedAuthenticationTypes()
+if (types.includes('facial_recognition')) {
// ...
}

-const result = await LocalAuthentication.authenticateAsync({ promptMessage: 'Unlock' })
+const result = await LocalAuthentication.authenticate({ promptMessage: 'Unlock' })

Method mapping​

expo-local-authenticationnitro-local-auth
hasHardwareAsync()hasHardware()
isEnrolledAsync()isEnrolled()
supportedAuthenticationTypesAsync()getSupportedAuthenticationTypes()
getEnrolledLevelAsync()getEnrolledLevel()
authenticateAsync(options)authenticate(options)
cancelAuthenticate() (Android only, async)cancelAuthenticate() (iOS and Android, synchronous)
noneisLockedOut()

Value mapping​

Expo enum memberString value
AuthenticationType.FINGERPRINT'fingerprint'
AuthenticationType.FACIAL_RECOGNITION'facial_recognition'
AuthenticationType.IRIS'iris'
none'optic_id'
SecurityLevel.NONE'none'
SecurityLevel.SECRET'secret'
SecurityLevel.BIOMETRIC_WEAK'biometric_weak'
SecurityLevel.BIOMETRIC_STRONG'biometric_strong'