【问题标题】:Send firebase auth verification email using javascript and getuser [duplicate]使用javascript和getuser发送firebase身份验证电子邮件[重复]
【发布时间】:2019-07-13 13:30:45
【问题描述】:

我正在尝试使用 firebase auth admin 向用户发送电子邮件验证。所有示例似乎都使用 firebase.auth().currentUser;但是,在我的情况下,我以管理员用户身份登录,查看用户的自定义仪表板列表以执行操作,而不是以个人用户身份登录。

我可以使用这种方法成功地更改用户记录,方法是将 UID 传递给 updateUser 方法和更改...例如

let userRecord = await fbAuth.updateUser(blogUID, {
          email: req.body.BloggerEmail
})

并且可以检索我想要使用的用户的用户详细信息:

    var userA = await fbAuth.getUser(blogUID)

但是,此方法返回的用户对象不允许我调用 sendEmailVerification 方法(似乎 getUser 不会返回与 getCurrentUser 相同的对象类型

    try {
        var userA = await fbAuth.getUser(blogUID).sendEmailVerification()
        console.log("Sent new verification email");
    } catch(error) {
        console.log("Error sending verification email " + error);
    }

[失败,sendEmailVerification 不是方法]

我尝试使用的官方参考文档: https://firebase.google.com/docs/auth/web/manage-users#send_a_user_a_verification_email

感谢您的帮助。

【问题讨论】:

    标签: javascript firebase firebase-authentication firebase-admin


    【解决方案1】:

    由于您的代码使用 Admin SDK 通过 UID 查找用户,因此它只能调用来自 Admin SDK 的方法。您不能简单地匹配来自 Admin SDK 和客户端 SDK 的方法。

    由于 Admin SDK 没有发送验证电子邮件的方法(请参阅 this),您要么必须让客户端执行此操作,要么实施您自己的电子邮件验证流程。见firebase admin SDK create user and send verification email

    【讨论】:

    • 我已经查看了这篇文章 - 这很有道理,我还会向 Firebase 提出另一个更改请求。
    猜你喜欢
    • 2018-08-07
    • 1970-01-01
    • 2023-03-18
    • 2021-12-08
    • 2018-02-10
    • 1970-01-01
    • 2017-09-09
    • 2011-06-18
    • 2015-11-23
    相关资源
    最近更新 更多