- Add rn-local-authentication to your dependencies
yarn add rn-local-authenticationor, for npm use
npm install rn-local-authentication --save- Link native dependencies
2.1 react-native >= 0.60
Autolinking will take care of the link step, but for iOS, don't forget to run pod install in ios/ folder
If you haven't set up cocoapods yet, please refer to that article
2.2 react-native < 0.60
You have to call link command manualy:
react-native link rn-local-authenticationFor manual linking, please refer to:
- that article for Android
- react-native own tutorial for iOS
- Additional step for FaceID devices:
Important
IOS
Include the NSFaceIDUsageDescription key in your app’s Info.plist file if your app allows biometric authentication. Otherwise, authorization requests may fail.
Android
Add these permissions to AndroidManifest.xml
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />Add following to app/src/build.gradle
implementation "androidx.biometric:biometric:1.1.0"- Import
LocalAuthenticationinto your component
Minimal example with ios & android:
import React from 'react';
import LocalAuthentication from 'rn-local-authentication';
class MyComponent extends React.Component {
componentDidMount() {
LocalAuthentication.authenticateAsync({
reason: "Please, authenticate!"
}).then(response => {
if (response.success) {
Alert.alert("Authenticated successfully!");
} else {
Alert.alert("Something went wrong");
}
})
}
render() {
return (<AnotherComponent />);
}
}Next, check out Api Reference