Search code examples
firebasefirebase-authenticationreact-nativereact-native-firebase

Firebase Phone Authentication error in React Native Code


I am trying to build a React Native app and firebase authentication. I am getting the Error:

RecaptchaVerifier is only supported in a browser HTTP/HTTPS environment with DOM support

auth
      .signInWithPhoneNumber(number, appVerifier)) // <- this is where captcha is added
      .then((result) => {
        this.setState({ confirm: result });
        this.setState({ buttonText: "Verify OTP" });
        this.setState({ isLoading: false });
      })
      .catch((err) => {
        console.log(`Error in phone auth: ${err}`);
      });

The version which I am using of firebase is "react-native-firebase": "^5.6.0" When I remove second parameter it gives an error which states two parameter required, found one


Solution

  • Are you sure you are using react-native-firebase phone auth with 5.X.X version. You can skip the appverifier from the method and instead use the following method from react-native-firebase. It will automatically open a window to verify the app and recaptha.

    firebase.auth().signInWithPhoneNumber(phoneNumber)
    .then(confirmResult => // save confirm result to use with the manual verification code)
    .catch(error => /error);