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

查看:179
本文介绍了如何使用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()函数,以便用户 注册他的新密码.
  • Once the user has been created I send an email to verify your email with the function user.sendEmailVerification ().
  • As the user was created by another user, I assign a default password and use the sendPasswordResetEmail () function so that the user registers his new password.

到目前为止,这对我来说效果很好,但由于许多原因,现在我需要将该逻辑移至服务器,因为我正在开发具有云功能的后端,并且我正在使用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身份验证中?
  1. How can I make the sendEmailVerification () and sendPasswordResetEmail () functions work on the server?
  2. How can I make the link generated with auth.generatePasswordResetLink (email) work correctly on the server?
  3. Is there any way to use templates and emails on the server that are in firebase auth?

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

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

推荐答案

  1. 这些功能在firebase-admin中不可用,但是您也应该能够在服务器上运行客户端SDK(firebase).这并不是最佳做法,但可以完成工作.长期以来,打开功能请求即可在Admin中支持此功能SDK.您会在那里找到一些有用的提示和解决方法.
  2. 可能是一个错误.我会考虑将其报告为完整且最少的repro. 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天全站免登陆