5

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?

2 Answers 2

7

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(() => {
  ...
});
Sign up to request clarification or add additional context in comments.

1 Comment

The current way to do this would be this.af.auth.currentUser.then(user => {user.updatePassword(password)});
1

I have once faced this problem and have not got an angularfire2 answer yet.

Here is a native firebase way I get through this problem.

public auth: any;
constructor(@Inject(FirebaseApp) firebaseApp: any) {
  this.auth = firebaseApp.auth();
}

reset(targetEmail: any) {
  this.auth.sendPasswordResetEmail(targetEmail);
}

Note:

It seems we could not change the password directly, only to send a password reset eamil to the target email address.

1 Comment

Pengyy how can I use script in Angular 4? I have use the package angularfire2 but its very difficult to use and is there any easy way to use firebase in my application?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.