Firebase Magic Email链接以及密码登录 [英] Firebase Magic Email link together with Password Login

查看:72
本文介绍了Firebase Magic Email链接以及密码登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们今天激活了电子邮件链接,但想转到常规的电子邮件+密码登录.

We have Email Link active today but would like to go over to a regular email+password login.

要实现此目的,我们需要创建被遗忘的密码,创建帐户等页面.

To implement this we need to create forgoten pw, create account, etc pages.

我不能只禁用它,因为那样用户将无法登录生产.我想知道电子邮件链接"是否处于活动状态,您仍然可以使用忘记的密码并通过密码登录吗?我们不想为另一个Firebase项目付钱,只是为了能够在切换之前对其进行测试.

I cannot just disable it because then users won't be able to login in prod. I'm wondering though if "Email link" is active can you still use forgotten password and login via Password? We don't want to pay for another Firebase project just to be able to test this before we switch over.

我已经实现了忘记密码,但是我在本地没有收到电子邮件,我确实收到了通过链接电子邮件进行的登录,甚至在本地也可以使用.

I have implemented forgotten password but I receive no email locally, the login via Link email I do recieve and it works even locally.

如果该电子邮件已经存在,但我只是没有收到任何电子邮件,则调用以下内容时,没有错误报告;如果该电子邮件不存在,它将返回错误.

There are no errors reported when the below is called if the email already exists but I just don't receive any email, if the email doesn't exist it returns an error.

这与此有关吗?在Cloud Functions for Firebase中调用sendPasswordResetEmail()

const admin = require('firebase-admin')

const serviceAccount = require('./yadayada')

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'https://something.firebaseio.com',
})    

router.post('/forgot', async (req, res) => {
  const { env } = req

  try {
    const { email } = req.body
    console.log('forgot', email)
    await admin.auth().generatePasswordResetLink(email)
    res.status(200).send('ok')
  } catch (error) {
    if (env !== 'production') {
      res.status(200).send(error.message)
    } else {
      // maybe the user didn't exist but we don't want to let hackers know which emails exist!
      res.status(200).send('ok')
    }

    console.log(error.message)
  }
})

推荐答案

(服务器端):

显然,它只是创建了一个链接,您必须自己处理通过电子邮件发送的链接.##"##%Q#

Apparently it just creates a link and you have to deal with sending that in an email yourself.. #"##%Q#

await admin.auth().generatePasswordResetLink(email, {
  url: continueUrl,
})
  .then((link) => {
    // The link was successfully generated.
    // @todo send this link to email yourself b****
  })
  .catch((error) => {
    // Some error occurred, you can inspect the code: error.code
  })

然后您需要您的SMTP详细信息并安装此 https://firebase.google.com/products/extensions/firestore-send-email

And then you need your SMTP details and install this https://firebase.google.com/products/extensions/firestore-send-email

毫无意义,因为它本身就发送了魔术登录链接,并且已经有一个被忘记的密码模板...但是到目前为止,我至少发现了所有这些信息...

Makes no sense since it sends the magic login link all by itself and there is already a forgotten password template... but it's all I found so far at least...

免费且容易版本,但没有易于管理的电子邮件模板: https://stackoverflow.com/a/58938290/846348

Free and easier version but without easy to manage email templates: https://stackoverflow.com/a/58938290/846348

编辑:如果您使用客户端方法,则确实会发送电子邮件,并且您可以配置模板在Firebase中的外观,但是看来您不能使用< table> 标记,所有精美的html-email都使用该标记,因此您实际上无法以任何不错的方式对其进行样式设置.

EDIT: If you use the clientside approach it does send the email and you can configure how the template looks inside firebase, however it seems you then cannot use <table> tags which all fancy html-emails use so you can't really style it in any nice way then instead..

sendPasswordResetEmail(email)

这篇关于Firebase Magic Email链接以及密码登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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