12

I am using react-native-fingerprint-scanner for Touch ID, Face Id, Passcode authentication.

Touch ID is working for me but How can I check if device support or not?

I have tried using react-native-touch-id but it is not for Face Id on android.

Is there any way to achieve this for both platforms (iOS/Android)?

Reference:Link

enter image description here

enter image description here

Sagar
  • 5,273
  • 4
  • 37
  • 50

5 Answers5

2

react-native-touch-id supports FaceId too. But, is not actively maintained anymore. So, they recommend to use expo local authentication. It works in all react native applications regardless of expo or not.

To use this, first you have to install react-native-unimodules. follow this guide https://docs.expo.io/bare/installing-unimodules/

Once it is installed you can install it by

npm install expo-local-authentication

add following line to your import

import LocalAuthentication from 'expo-local-authentication';

After that, we can use it.

async function biometricAuth(){
  const compatible = await LocalAuthentication.hasHardwareAsync();
  if (compatible) {
    const hasRecords = await LocalAuthentication.isEnrolledAsync();
    if (hasRecords) {
      const result = await LocalAuthentication.authenticateAsync();
      return result;
    }
  }
}

It will automatically choose between available local authentication (TouchID, FaceID, Number lock, Pattern lock etc) and authenticate the user.

Sagar
  • 5,273
  • 4
  • 37
  • 50
Haseeb A
  • 5,356
  • 1
  • 30
  • 34
  • Yes, it is for react native. Expo team made it supported for RN. Follow the steps above. – Haseeb A Nov 20 '20 at 14:13
  • "import * as LocalAuthentication from 'expo-local-authentication'; " should be right here. – Peanut Shi May 31 '21 at 10:50
  • This solution doesn't work for android devices which supports only face recognition unlock. Do you know any solution? I provided precise question here: https://stackoverflow.com/questions/73391435/face-id-biometry-face-recognition-unlock-on-android-devices-in-react-native – Piotr Witkoś Aug 23 '22 at 10:44
1

react-native-touch-id should work for both TouchID and FaceID.

iOS allows the device to fall back to using the passcode, if faceid/touch is not available. this does not mean that if touchid/faceid fails the first few times it will revert to passcode, rather that if the former are not enrolled, then it will use the passcode.

from the docs

You can check to see if its supported first.

const optionalConfigObject = {
  fallbackLabel: 'Show Passcode', 
  passcodeFallback: true,
}

TouchID.isSupported(optionalConfigObject)
  .then(biometryType => {
    // Success code
    if (biometryType === 'FaceID') {
        console.log('FaceID is supported.');
    } else {
        console.log('TouchID is supported.');
    }
  })
  .catch(error => {
    // Failure code
    console.log(error);
  });
johnborges
  • 2,422
  • 20
  • 33
0

enter image description here // use this package import RNBiometrics from "react-native-simple-biometrics"; this is both for touchId and passcode for android and ios

0

react-native-touch-id will work for both TouchID and FaceID

I have updated the repo so now if you want to use passcode after face ID or Touch ID fails than use will be prompted to enter the PIN (only for ios)checkout my repo

https://github.com/avaiyakapil/react-native-touch-id

import TouchID from 'react-native-touch-id';

TouchID.authenticate('Authentication')
     .then(success => {
              // Success code
            })
            .catch(error => {
              // Failure code
            });
-2
//this code is for checking whether touch id is supported or not
    TouchID.isSupported()
          .then(biometryType => {
            // Success code
            if (biometryType === 'FaceID') {
              console.log('FaceID is supported.');
            } else if (biometryType === 'TouchID'){
              console.log('TouchID is supported.');
            } else if (biometryType === true) {
              // Touch ID is supported on Android
        }
          })
          .catch(error => {
            // Failure code if the user's device does not have touchID or faceID enabled
            console.log(error);
          });
Sameer Ahmed
  • 9
  • 1
  • 2