如何使用 firebase-admin SDK 在服务器上使用 sendPasswordResetEmail() 函数? [英] How to use the sendPasswordResetEmail() function on the server using the firebase-admin SDK?

查看:26
本文介绍了如何使用 firebase-admin SDK 在服务器上使用 sendPasswordResetEmail() 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,我在 Web 客户端中使用了 firebase.auth,一旦用户创建另一个用户,我就会链接某些安全逻辑:

In the past, I have used firebase.auth in the web client and once a user creates another user, I link certain security logic:

  • 创建用户后,我会发送一封电子邮件来验证您的电子邮件使用函数 user.sendEmailVerification ().
  • 由于该用户是由另一个用户创建的,所以我分配了一个默认密码并使用 sendPasswordResetEmail() 函数使用户注册他的新密码.

到目前为止,这对我来说效果很好,但是现在出于多种原因,我需要将该逻辑移至我的服务器,为此我正在开发具有云功能的后端,并且我正在使用Node.js Firebase Admin SDK 版本 6.4.0,但我找不到使用 user.sendEmailVerification() 和 sendPasswordResetEmail() 函数在服务器上实现相同逻辑的方法,我发现最接近的是:

That has worked well for me so far, but now for many reasons I need to move that logic to my server, for that I'm developing a backend with cloud functions and I'm using the Node.js Firebase Admin SDK version 6.4.0, but I can not find a way to use the functions of user.sendEmailVerification() and sendPasswordResetEmail() to implement the same logic on the server, the closest thing I found was:

  • auth.generateEmailVerificationLink(电子邮件)
  • auth.generatePasswordResetLink(电子邮件)

但它只为每一个生成一个链接,顺便说一下,唯一的 emailVerification() 为我服务,来自 generatePasswordReset 的那个总是告诉我:

But it only generates a link for each one, which by the way the only emailVerification() serves me, the one from generatePasswordReset always tells me:

再次尝试重置密码

您重设密码的请求已过期或链接已失效已经用过了.

Your request to reset your password has expired or the link has already been used.

即使是一个新链接,也没有被使用过.

Even though be a new link, and it has not been used.

我的 3 个问题是:

  1. 如何使 sendEmailVerification () 和sendPasswordResetEmail() 函数在服务器上工作吗?
  2. 如何生成链接auth.generatePasswordResetLink(电子邮件)在服务器上正常工作?
  3. 有没有办法在服务器上使用模板和电子邮件?在 Firebase 身份验证中?

预先感谢您与我以及所有程序员社区的堆栈溢出分享您的经验.

Thank you in advance for sharing your experience with me, with all the programmers' community of stack overflow.

推荐答案

  1. 这些功能在 firebase-admin 中不可用,但您应该也可以在服务器上运行客户端 SDK (firebase).不完全是最佳实践,但它会完成工作.长期以来,开放功能请求支持管理中的此功能开发工具包.您会在那里找到一些有用的提示和解决方法.
  2. 可能是一个错误.我会考虑将它与完整和最小的再现一起报告.Admin SDK 确实有一个 此用例的集成测试用例,但工作方式略有不同.
  3. 目前没有.希望当上述功能请求最终得到满足时,这将得到解决.
  1. Those functions are not available in firebase-admin, but you should be able to run the client-side SDK (firebase) on the server as well. Not exactly a best practice, but it will get the job done. There's a long standing open feature request to support this functionality in the Admin SDK. You will find some helpful tips and workarounds there.
  2. Could be a bug. I would consider reporting it along with a complete and minimal repro. The Admin SDK does have an integration test case for this use case, but it works slightly differently.
  3. Not at the moment. Hopefully, this will be covered when the above feature request is eventually fulfilled.

这篇关于如何使用 firebase-admin SDK 在服务器上使用 sendPasswordResetEmail() 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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