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

查看:21
本文介绍了使用 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() 来自相应客户端 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.

请注意,Admin SDK 的第二个选项与 Client 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天全站免登陆