Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you update a user in Firebase using AngularFire2?

I can easily use this to create a user:

this.af.auth.createUser({email: email, password: password});

but how do I edit the users details once they're created? (ie: Change the password or the e-mail address?). I would think something like this:

this.af.auth.updateUser({email: email, password: password});

But there's no updateUser method?

like image 480
Jus10 Avatar asked Mar 09 '23 17:03

Jus10


1 Answers

With AngularFire2 you just need to add "currentUser" to your path.

this.af.auth.currentUser.updateEmail(email)
.then(() => {
  ...
});

You will also need to reauthenticate the login prior to calling this as Firebase requires a fresh authentication to perform certain account functions such as deleting the account, changing the email or the password.

For the project I just implemented this on, I just included the login as part of the change password/email forms and then called "signInWithEmailAndPassword" just prior to the "updateEmail" call.

To update the password just do the following:

this.af.auth.currentUser.updatePassword(password)
.then(() => {
  ...
});
like image 135
oddpixel Avatar answered Apr 01 '23 13:04

oddpixel