user992731
user992731

Reputation: 3520

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

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

Upvotes: 1

Views: 1148

Answers (1)

Ti Wang
Ti Wang

Reputation: 785

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

Upvotes: 3

Related Questions