使用javascript和getuser发送Firebase身份验证电子邮件

时间:2019-02-19 23:29:21

标签: javascript firebase firebase-authentication firebase-admin

我正在尝试使用Firebase身份验证管理员向用户发送电子邮件验证。所有示例似乎都使用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

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

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

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

相关问题