updatePhoneNumber failed: First argument “phoneCredential” must be a valid phone credential

我怕爱的太早我们不能终老 提交于 2021-02-10 17:38:15

问题


I am trying to updatePhoneNumber and keep getting the following error above. Looking at the docs I was under the impressing this is a method?

Js:

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

I tried setting this in the updateProfile Method as well and still no luck.

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

回答1:


updatePhoneNumber requires a phone credential since the phone number needs to be verified by 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);
    });


来源:https://stackoverflow.com/questions/54780653/updatephonenumber-failed-first-argument-phonecredential-must-be-a-valid-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!