React Native Library to handle the biometric autentication. The library is developed with Turbomodules, for this reason to make it work is necessary use RN 0.68 or higher
npm install react-native-biometrics-scanneror
yarn add react-native-biometrics-scannerIn your Info.plist:
<key>NSFaceIDUsageDescription</key>
<string>{Add here a message}</string>
In order to make it work you need to add the necessary Permissions in your AndroidManifest.xml:
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
import { getAvailableBiometric } from "react-native-biometrics-scanner";
// ...
const result = await getAvailableBiometric();This method return the type of biometric present on the device:
- iOS:
TouchIDorFaceID - Android:
TouchIDorFaceIDorIrisIDor if it is not possible to retrieve any infoBiometricID
and throws:
UnknownBiometricErrorwhen the status of biometric is unknownUnsupportedBiometricErrorwhen the biometric is not supported by the deviceNoEnrollErrorwhen user needs to enroll in order to use biometric
import { authenticate } from "react-native-biometrics-scanner";
// ...
await authenticate(prompt);It requires an object to configure the prompt message:
promptMessage: the message to showallowDeviceCredentials: if true the system fallback is used to authenticate after all the attempts of biometric fail, otherwiseBiometricFallbackErroris throwncancelButtonText: the text for cancel button (Android only)(optional)descriptionText: the text for description (Android only)(optional)subtitleText: the text for subtitle (Android only)(optional)fallbackPromptMessage: the title of fallback option (iOS only)(optional)
This method resolve a promise if the authentication is succesful and throws:
BiometricUnknownErrorwhen the status of biometric is unknownBiometricUnsupportedErrorwhen the biometric is not supported by the deviceBiometricNoEnrollErrorwhen user needs to enroll in order to use biometricBiometricAuthenitcationErrorwhen the authentication failsBiometricUserCancelErrorwhen user cancels the authenticationBiometricPasscodeNotSetErrorwhen a passcode is not setBiometricLockOutErrorwhen the device is lockedBiometricFallbackErrorwhen the biometric authentication fails and a fallback has to be providedBiometricPasscodeNotSetErrorwhen passcode is not setBiometricSystemCancelError(iOS only) when the system cancels the authentication
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT