第二个参数applicationverifier必须是firebase.auth.applicationverifier的实现

时间:2019-05-03 10:32:44

标签: javascript firebase react-native firebase-authentication

第二个参数applicationverifier必须是firebase.auth.applicationverifier的实现

 .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;
    //
    alert("SMS sent");
  })
  .catch(function(error) {
    // Error; SMS not sent
    // ...
    alert("Error ! SMS not sent");
  });



 initReCaptcha() {
setTimeout(() => {
  let vm = this;
  window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier(
    "recaptcha-container",
    {
      size: "invisible",
      callback: function(response) {
        // reCAPTCHA solved, allow signInWithPhoneNumber.
        // ...
      },
      "expired-callback": function() {
        // Response expired. Ask user to solve reCAPTCHA again.
        // ...
      }
    }
  );
  //
  this.appVerifier = window.recaptchaVerifier;
}, 1000);
}

created() {
  this.initReCaptcha();
}

我将应用程序验证程序设置为第二个参数,但会产生错误,我该怎么办

1 个答案:

答案 0 :(得分:1)

我看不出您在上述逻辑中延迟appVerifier初始化的原因。

调用时很可能appVerifier尚未初始化:

signInWithPhoneNumber(phoneNumber, appVerifier)