【问题标题】:updatePhoneNumber failed: First argument "phoneCredential" must be a valid phone credentialupdatePhoneNumber 失败:第一个参数“phoneCredential”必须是有效的电话凭据
【发布时间】:2019-02-20 07:06:43
【问题描述】:

我正在尝试更新PhoneNumber 并不断收到上面的以下错误。看着我印象深刻的文档,这是一种方法?

Js:

user.updatePhoneNumber({
  phoneNumber: "+15618104444",
});

我也尝试在 updateProfile 方法中设置它,但仍然没有成功。

user.updateProfile({
  displayName: displayName,
  photoURL: photoURL,
  phoneNumber: "+15618104444"
});

【问题讨论】:

    标签: firebase firebase-authentication


    【解决方案1】:

    updatePhoneNumber 需要电话凭据,因为电话号码需要通过 SMS 验证。

    // 'recaptcha-container' is the ID of an element in the DOM.
    var applicationVerifier = new firebase.auth.RecaptchaVerifier(
        'recaptcha-container');
    var provider = new firebase.auth.PhoneAuthProvider();
    provider.verifyPhoneNumber('+16505550101', applicationVerifier)
        .then(function(verificationId) {
          var verificationCode = window.prompt('Please enter the verification ' +
              'code that was sent to your mobile device.');
          return firebase.auth.PhoneAuthProvider.credential(verificationId,
              verificationCode);
        })
        .then(function(phoneCredential) {
          return user.updatePhoneNumber(phoneCredential);
        });
    

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 1970-01-01
      • 2021-12-22
      • 2018-08-20
      • 1970-01-01
      • 2019-08-07
      • 1970-01-01
      • 1970-01-01
      • 2020-04-01
      相关资源
      最近更新 更多