naoufal/react-native-touch-id

How to catch LAErrorUserCancel ?

jorisw opened this issue · 1 comments

I'm using react-native-touch-id 4.4.1 against react-native 0.57.3 in the iOS Simulator.

When a user fails to match biometrics, then cancels the Face ID (in my case) prompt, an error is thrown that makes React Native show a full screen red stack trace, that I can't seem to catch:

LAErrorUserCancel: Authentication was canceled by the user—for example, the user tapped Cancel in the dialog.

How do I catch this error to handle it gracefully?

A code snippet:

handleVerifyBio(promptMessage) {
   try {
      const userBioAuthenticated = await Biometrics.authenticate(promptMessage, {});

      console.log({userBioAuthenticated}); // not printed
      
      if(userBioAuthenticated){
        return true;
      }

    } catch (error) {
      console.error(error); // not printed
    }
}

To answer my own question: react-native-touch-id can only be used with the .then() syntax, or you won't properly catch thrown errors.