react-nativefingerprintbiometricstouch-idface-id

How to check if device has sensor for authentication with biometrics? (react-native-fingerprint-scanner)


I am using this library to authenticate with biometrics sensor such as face ID or fingerprint scanner but I would like to know how to detect whether the device has a sensor or not : react-native-fingerprint-scanner

according to it's documentation there is an API called .isSensorAvailable() but I dont understand what does it return in case there isn't any available sensor in the device.


Solution

  • You can use the .isSensorAvailable() API like this example below.

    import FingerprintScanner from 'react-native-fingerprint-scanner'
    
        FingerprintScanner
                    .isSensorAvailable()
                    .then(() => {
                    // Call the Fingerprint Scanner Method
                        FingerprintScanner
                            .authenticate({ description: 'Authenticate to access this' })
                            .then(() => {
                                // Method for Authentication
                                onAuthenticate()
                            })
                            // Call error method
                            .catch(error => onAuthenticationFailure(error))
    
                    })
                     //Call the error method
                    .catch(error => onAuthenticationFailure(error))