首页 > 解决方案 > Firebase - 电话号码验证

问题描述

所以我正在构建一个简单的应用程序,我想要电话号码身份验证。但是,按照网站上的说明进行操作后,似乎没有任何反应。

// App.js

handleNext = () => {
    verifyPhoneNumber(this.state.phoneNumber);
    this.setState(prevState => ({
      activeStep: prevState.activeStep + 1
    }));
  };
...
<Button
         size="small"
         onClick={this.handleNext}
         disabled={activeStep === maxSteps - 1}
         id={"verify-phone-number-button"}
         >
         Next
</Button>

//Controller.js
export const verifyPhoneNumber = (phoneNumber) => {
  console.log(phoneNumber) // +14084445555
  firebase.auth().useDeviceLanguage();
  window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('verify-phone-number-button', {
    'size': 'invisible',
    'callback': function (response) {
      // reCAPTCHA solved, allow signInWithPhoneNumber.
      console.log("reCAPTCHA solved")
      var appVerifier = window.recaptchaVerifier;
      firebaseApp.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
        .then(function (confirmationResult) {
          // SMS sent. Prompt user to type the code from the message, then sign the
          // user in with confirmationResult.confirm(code).
          window.confirmationResult = confirmationResult;
          console.log("success")
        }).catch(function (error) {
          console.log(error)
          // Error; SMS not sent
          // ...
        });
    }
  });
}

reCAPTCHA solved永远不会被打印意味着它永远不会在那里。但是,它也没有打印任何错误消息,所以我不确定发生了什么。

谢谢你的帮助!

标签: reactjsfirebasefirebase-authentication

解决方案


推荐阅读