Javascript 如何在firebase auth中更改电子邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39909964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 23:03:19  来源:igfitidea点击:

How to change email in firebase auth?

javascriptfirebasefirebase-authentication

提问by CENT1PEDE

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

我正在尝试使用以下方法更改/更新用户的电子邮件地址:

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

But I am getting ...changeEmail is not a functionerror. I found the reference herefrom the old firebase docu.

但我得到...changeEmail 不是函数错误。我发现参考这里从老火力实况。

So how to I do it in the 3.x version? Because I cant find a reference in the new documentation.

那么如何在 3.x 版本中做到这一点呢?因为我在新文档中找不到参考。

回答by Frank van Puffelen

You're looking for the updateEmail()method on the firebase.Userobject: https://firebase.google.com/docs/reference/js/firebase.User#updateEmail

您正在寻找对象的updateEmail()方法firebase.Userhttps: //firebase.google.com/docs/reference/js/firebase.User#updateEmail

Since this is on the user object, your user will already have to be signed in. Hence it only requires the password.

由于这是在用户对象上,您的用户必须已经登录。因此它只需要密码。

Simple usage:

简单用法:

firebase.auth()
    .signInWithEmailAndPassword('[email protected]', 'correcthorsebatterystaple')
    .then(function(userCredential) {
        userCredential.user.updateEmail('[email protected]')
    })

回答by Robin Wieruch

If someone is looking for updating a user's email via Firebase Admin, it's documented over hereand can be performed with:

如果有人正在寻找通过Firebase Admin更新用户的电子邮件,它会记录在此处并且可以通过以下方式执行:

admin.auth().updateUser(uid, {
  email: "[email protected]"
});

回答by oddpixel

You can do this directly with AngularFire2, you just need to add "currentUser" to your path.

您可以直接使用 AngularFire2 执行此操作,您只需要将“currentUser”添加到您的路径中。

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.

您还需要在调用之前重新验证登录名,因为 Firebase 需要全新的身份验证才能执行某些帐户功能,例如删除帐户、更改电子邮件或密码。

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.

对于我刚刚实施的项目,我只是将登录名作为更改密码/电子邮件表单的一部分,然后在“updateEmail”调用之前调用了“signInWithEmailAndPassword”。

To update the password just do the following:

要更新密码,只需执行以下操作:

this.af.auth.currentUser.updatePassword(password)
.then(() => {
  ...
});