How to change email in firebase auth?

前端 未结 4 2042
-上瘾入骨i
-上瘾入骨i 2020-12-29 20:08

I am trying to change/update a user\'s email address using :

firebase.auth().changeEmail({oldEmail, newEmail, password}, cb)

But I am getti

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-29 20:54

    You can do this directly 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(() => {
      ...
    });
    

提交回复
热议问题