I have implemented a react-native-fingerprint-scanner
, it's working for Touch Id
.
Now I wanted to add authentication for Touch ID, Face Id, Passcode for both platform
Is there any way to check whether your device support or not. Also, 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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With