首页 > 解决方案 > React Native 代码中的 Firebase 电话身份验证错误

问题描述

我正在尝试构建一个 React Native 应用程序和 firebase 身份验证。我收到错误:

RecaptchaVerifier 仅在支持 DOM 的浏览器 HTTP/HTTPS 环境中受支持

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}`);
      });

我正在使用的 firebase 版本是"react-native-firebase": "^5.6.0" 当我删除第二个参数时,它会给出一个错误,指出需要两个参数,找到一个

标签: firebasereact-nativefirebase-authenticationreact-native-androidreact-native-firebase

解决方案


您确定您使用的是react-native-firebase5.XX 版本的电话身份验证。您可以从方法中跳过 appverifier,而是使用react-native-firebase. 它将自动打开一个窗口来验证应用程序和 recaptha。

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

推荐阅读