Skip to content

Latest commit

 

History

History
87 lines (58 loc) · 2.12 KB

File metadata and controls

87 lines (58 loc) · 2.12 KB

React Native Local Authentication Getting Started Guide

  1. Add rn-local-authentication to your dependencies
yarn add rn-local-authentication

or, for npm use

npm install rn-local-authentication --save
  1. 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-authentication

For manual linking, please refer to:

  1. 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"
  1. Import LocalAuthentication into 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