I am using firebase in my create-react-app project.
For SignUp purpose I am using
firebaseAuth().createUserWithEmailAndPassword(email, password)
Then after SignUp I am saving their phoneNumber in localStorage and redirect them to PhoneAuth page using then I am using this function
export function PhnAuth(phone) {
window.recaptchaVerifier = new firebaseAuth.RecaptchaVerifier('recaptcha-container',{'size': 'small'});
return firebaseAuth().currentUser.linkWithPhoneNumber(phone, window.recaptchaVerifier)
.then(function (confirmationResult) {
window.confirmationResult = confirmationResult;
}).catch(function (error) {
})
}
After the recaptcha and all done I get the I successfully linked the user's email with their phoneNumber. But how to update that phoneNumber later ? I couldn't find anything regarding updating a linked phoneNumber in the docs.
There's an updatePhoneNumber
method on the User
object for that purpose.
See the reference docs and the documentation on updating a user's profile.
Note that you'll need a phoneCredential
for this, meaning that this must be a verified phone number. See how to update user phone number in firebase.auth (js, ts).
If you want to update a user's phone number without verifying it, that can be done from the Admin SDK. For an example of this, see How to update phone number on Firebase Authentication in NodeJS?