Firebase自定义验证电子邮件 [英] Firebase custom verification email

查看:45
本文介绍了Firebase自定义验证电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关此主题的其他文章,但最终无法弄清楚如何完成此任务.

我要发送的电子邮件验证电子邮件通常是从Firebase本身从我自己的电子邮件提供商(例如mailjet等)发送的.原因是我要自定义电子邮件文本等.

我还阅读了有关


然后,当用户单击他/她收到的电子邮件中的链接时,您需要按照问题中提到的文档中的说明进行操作:

在您应用的页面中 https://www.myrapp.com/emailVerifyScreen ,您可以从网址获取查询字符串值(例如 var actionCode = getParameterByName('oobCode'); ),然后使用这些值调用creating a custom email handler which I would do too. But this just handles the action that happens when the user clicks on the link in the email.

At the moment I call this from my flutter app after the users sign up:

user.sendEmailVerification();

this makes firebase send the standard verification email to the user. Instead of doing that I'd need to send the email myself. But like seen here I need to have this oobCode generated. to generate a correct link to handle. I just can't find an example on how to do that. What would be the right approach to send the email myself? Maybe I just did not find the right resource. Thanks a lot.

解决方案

You need to generate and send the email via a backend, by using the Admin SDK. The easiest is to use a Cloud Function, from which you use the Mailjet NodeJS API wrapper.

So, in the Cloud Function, you need to:

  1. Call the generateEmailVerificationLink() method of the Admin SDK, which returns a link
  2. Generate an email containing this link
  3. Send the email to the user (see the Mailjet NodeJS API wrapper documentation)

The first steps are detailed here in the doc.

In order to customize the URL of the verification link (e.g. you want to redirect to https://www.myrapp.com/emailVerifyScreen) you need to change the base URL as shown in the below image ("Customize action URL"). Also explained here in the doc.


Then, when the user clicks on the link in the email he/she has received, you need to do what is explained in the doc you referred to in your question: Create custom email action handlers. See the point #4 "Handle email address verification by calling applyActionCode".

Concretely, in the page of your app https://www.myrapp.com/emailVerifyScreen, you get the query string values from the URL (e.g. var actionCode = getParameterByName('oobCode');) and you use these values to call the applyActionCode(actionCode) method. When the promise returned by this method is fullfilled, you know that the email has been verified.

  var actionCode = getParameterByName('oobCode'); 
  auth.applyActionCode(actionCode).then((resp) => {
    // Email address has been verified.

    // TODO: Display a confirmation message to the user.
    // You could also provide the user with a link back to the app.

    // TODO: If a continue URL is available, display a button which on
    // click redirects the user back to the app via continueUrl with
    // additional state determined from that URL's parameters.
  }).catch((error) => {
    // Code is invalid or expired. Ask the user to verify their email address
    // again.
  });


One last point to note: you cannot directly get the oobCode alone. The generateEmailVerificationLink() method generates the full URL.

这篇关于Firebase自定义验证电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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