Migrating from expo-local-authentication
The API follows expo-local-authentication, with three differences:
- Status methods are synchronous. Only
authenticatereturns a promise. - Enums are string unions, such as
'facial_recognition'and'biometric_strong', instead of numeric enums. - Additions:
isLockedOutand theoptic_idauthentication 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-authentication | nitro-local-auth |
|---|---|
hasHardwareAsync() | hasHardware() |
isEnrolledAsync() | isEnrolled() |
supportedAuthenticationTypesAsync() | getSupportedAuthenticationTypes() |
getEnrolledLevelAsync() | getEnrolledLevel() |
authenticateAsync(options) | authenticate(options) |
cancelAuthenticate() (Android only, async) | cancelAuthenticate() (iOS and Android, synchronous) |
| none | isLockedOut() |
Value mapping
| Expo enum member | String 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' |