react-native-fingerprint-scanner
react-native-fingerprint-scanner copied to clipboard
Authentication was not successful because the user failed to provide valid credentials - throws randomly.
FingerprintScanner.authenticate({
onAttempt: this.handleAuthenticationAttempted
})
.then(() => {
console.log('success');
this.setState({ errorMessage: undefined });
this.handleFingerprintDismissed(true);
})
.catch(error => {
this.setState({ errorMessage: error });
console.log('errorr', error);
});
sometimes inside componentdidmount this method returns error
Authentication was not successful because the user failed to provide valid credentials.
even if user didn't scan finger.
+1
+1 Samsung S8
I have the same issue, though less random - on Android.
I use an auto logout feature. After auto logout is triggered, the fingerprint scanner shows Authentication was not successful because the user failed to provide valid credentials
To reset, I need to quit the app and restart.
Is there a way to programmatically reset the fingerprint scanner?
I solved the issue on my end.
If FingerprintScanner.release()
doesn't get called after you authenticate and before you use again it causes the issue.
componentWillUnmount() isn't getting called for a variety of reasons (bugs in RN modal) so instead in componentDidMount() I call FingerprintScanner.release()
before FingerprintScanner.isSensorAvailable()
and .authenticate()
I'm also using react-native-router-flux. Previously I was using Actions.nextView()
which was causing some problems. For my use I now use Actions.replace("nextView")
Getting the same error. FingerprintScanner.release()
does nothing at all.
+1
Hi all, I've recently been added as a collaborator on this repo and am getting up to speed on the different issues.
I think I understand the bug report, however, based on @kenkotch's posted work around I'm not sure what next steps are. I suppose one approach would be to always call .release()
on android when authentication succeeds or fails? If anyone has a potential fix to PR, would definitely appreciate it!
Hi,
calling the .release()
doesn't fix it for me. :(
it looks like the Java's onHostDestroy is never called from my understanding. and then when you try to use the fingerprint again the old context is being thrown to the native module and to the React Native Bridge.
[update]
after reading the Android Fingerprint docs, you need to wait 30+ seconds after 5 failed attempts. I will add a rate limiter from my side and will let you know.
@yoavapi thanks for the update. That sounds like it'd be good to add to the example app in this repo and/or to the readme. Any interest in doing a PR?
This issue has been there for a while. Is someone working on it? I too face the same issue where the fingerprint scanner throws unauthorised error.
@soumyamishra89 were you able to try @yoavapi's suggested workaround:
after reading the Android Fingerprint docs, you need to wait 30+ seconds after 5 failed attempts. I will add a rate limiter from my side and will let you know.
Alternatively, it looks like this PR: https://github.com/hieuvp/react-native-fingerprint-scanner/pull/44 might also help, specifically, the changes to bring in onStartFailedByDeviceLocked
.
@phillbaker The issue is not when the user has failed attempts. The issue is when the app is opened for the first time, the user has not attempted to unlock with fingerprint and still it shows failed attempt. May be the PR: #44 might help.
any update on this issue?
facing the same issue. calling FingerprintScanner.release() before authentication is not working.
To add to this: The issue is when the app is opened for the first time, the user has not attempted to unlock with fingerprint and still it shows failed attempt. Open the app -> minimize it -> bring the app in foreground -> bang there is an error.
To my surprise I was getting the same error on device lock. but when is used react-native-restart
to restart the app, the error was not replicated.
but error persists on app minimise.
Please fix this bug.
A workaround although a nasty one. Restart the app twice.
_handleAppStateChange = (nextAppState) => {
console.log(this.state.appState,nextAppState)
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
console.log('App has come to the foreground!');
RNRestart.Restart(); // Restart app once , works like a charm in case phone is locked and unlocked
}
this.setState({appState: nextAppState});
};
FingerprintScanner
.isSensorAvailable()
.then((biometryType) => {
FingerprintScanner
.authenticate({ onAttempt: self.handleAuthenticationAttempted })
.then(() => {
// do your stuff
})
.catch((error) => {
if(error.message == 'Authentication was not successful because the user failed to provide valid credentials.' && this.restart_count == 0){
this.restart_count == 1; // check to handle looping issue
RNRestart.Restart(); // Restart the app twice to handle is particular case
}
self.setState({ errMsg: error.message });
});
@soumyamishra89 , @phillbaker , @yoavapi any update on above ?
@dg92 i tried to create a PR by updating the android library used for this one...but could not make it work as the updated android library uses androidx and if i upgrade to androidx then i have other libraries which do not support it yet and throws error... So created my own native implementation for now and testing if it works fine.
but i am not a contributor to this library so also waiting for updates from the contributors.
Hi, this issue happens when you exit the react native app through the android back button
I had solved this issue by using the BackHandler module
after that, I had used the react-native-exit-app
package .. which forces the app to be fully killed not like the backHandler.exitApp()
method
below you will find the code implementation when the back button is pressed
Now just enter the app again ... and the issue is SOLVED 💃