【问题标题】:Sending email verification using Cloud Function [duplicate]使用 Cloud Function 发送电子邮件验证 [重复]
【发布时间】:2020-11-15 15:11:45
【问题描述】:

我正在客户端注册新用户,然后我在某处阅读,其他社区成员也告诉我,在 Cloud 中拥有此功能将自动触发它并在创建每个用户后发送一封电子邮件:

exports.sendWelcomeEmail = functions.region('europe-west6').auth.user().onCreate((user) => {
    user.sendEmailVerification().then(function () {
// Email sent.
    }).catch(function (error) {
// An error happened.
    });
});

问题是(根据文档)sendEmailVerification() 在 Admin SDK 中不起作用,仅在 Client SDK 中起作用。我在这里遗漏了什么吗?

【问题讨论】:

  • 向单个用户发送电子邮件或短信的方法仅在客户端SDK中可用,并且只能用于向当前登录的用户发送消息。

标签: node.js firebase firebase-authentication google-cloud-functions


【解决方案1】:

functions.auth.user().onCreate(user) 函数有一个用户参数user,它是一个UserRecord 类型。它没有sendEmailVerification

https://firebase.google.com/docs/reference/functions/providers_auth_#userrecord

sendEmailVerification,根据文档存在于客户端 SDK 中,通过https://firebase.google.com/docs/reference/js/firebase.User

截至 2020 年,存在尚未解决的现有 github 问题:https://github.com/firebase/firebase-admin-node/issues/46,其中有一些解决方法(涉及调用 REST API,或在服务器上安装 Firebase 客户端 SDK)

但是,如果您有 SMTP 服务器并希望通过它发送电子邮件,请参阅 https://firebase.google.com/docs/auth/admin/email-action-links

参考文献

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-09
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 2017-06-29
    • 2021-10-21
    相关资源
    最近更新 更多