使用Firebase Cloud功能创建用户后如何发送电子邮件验证? [英] How to send email verification after user creation with Firebase Cloud functions?

查看:75
本文介绍了使用Firebase Cloud功能创建用户后如何发送电子邮件验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建用户后,我正在尝试发送验证电子邮件.由于Firebase本身无法实现,因此我正在尝试使用云功能.

I'm trying to send the verification email after the user is created. Since there's no way on Firebase itself, I'm trying it with cloud functions.

我真的找不到很多有关它的文档.到目前为止,我试图做的是:

I cannot really find a lot of documentation about it. What I tried to do so far is:

exports.sendEmailVerification = functions.auth.user().onCreate(event => {
    return user.sendEmailVerification()
});

但是我收到未定义用户的错误.

But I get the error that user is not defined.

如何创建此功能?

谢谢!

推荐答案

有两种方法可以发送电子邮件验证":通过电子邮件发送给用户:

There are two possibilities to send an "email verification" email to a user:

  1. 已登录的用户请求发送验证电子邮件.为此,您从前端调用 sendEmailVerification() 方法从相应的Client SDK中获取.
  2. 通过一个管理SDK,您生成链接通过相应的方法(例如 > auth.generateEmailVerificationLink() (用于Node.js Admin SDK),然后您通过通过自己的机制发送的电子邮件发送此链接.所有这些操作都在后端完成,并且可以在Cloud Function中完成.
  1. The signed-in user requests that a verification email be sent. For that, you call, from the front-end, the sendEmailVerification() method from the appropriate Client SDK.
  2. Through one of the Admin SDKs, you generate a link for email verification via the corresponding method (e.g. auth.generateEmailVerificationLink() for the Node.js Admin SDK) and you send this link via an email sent through your own mechanism. All of that is done in the back-end, and can be done in a Cloud Function.

请注意,管理SDK的第二个选项与客户端SDK的第一个选项并不完全相似:在第二个选项中,您需要通过自己的机制发送电子邮件,而在第一种情况下,电子邮件是自动发送的由Firebase平台发送

Note that the second option with the Admin SDKs is not exactly similar to the first option with the Client SDKs: in the second option you need to send the email through your own mechanism, while in the first case, the email is automatically sent by the Firebase platform

如果您希望将该功能添加到Admin SDK中,建议您

If you'd like that ability to be added to the Admin SDK, I'd recommend you file a feature request.

这篇关于使用Firebase Cloud功能创建用户后如何发送电子邮件验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆