如何在更改密码时触发 Firebase 中的云功能? [英] How to trigger a cloud function in Firebase on password change?

查看:16
本文介绍了如何在更改密码时触发 Firebase 中的云功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在用户更改密码时触发 Firebase 云功能,无论是通过更改密码 (firebase.auth().currentUser. updatePassword(newPassword) ) 或重置密码 (firebase.auth(). sendPasswordResetEmail(email) ).由于我没有在任何地方存储密码,因此我无法使用 .onUpdate 触发器(或任何其他触发器).

I am trying to trigger a Firebase cloud function when a user changes their password, be it by changing the password (firebase.auth().currentUser. updatePassword(newPassword) ) or by reseting it (firebase.auth(). sendPasswordResetEmail(email) ). Since I am not storing password anywhere I can not use .onUpdate trigger (or any other of the triggers).

我发现了一个类似的问题,但它只询问了密码更改的触发器,并且没有关于解决方法的信息:用于更改密码的 Firebase 云函数监听器

I found a similar question, but it only asked about a trigger on password change and there is no info about a workaround: Firebase cloud function listener for password change

使用此触发器,我想向用户发送一封电子邮件,说明他们的密码已更改.

with this trigger I want to send an email to user that their password has been changed.

有人有什么想法吗?有可能吗?

Does anyone have any ideas? Is it possible at all?

推荐答案

你想要的完全有可能,但你必须自己实现.正如您找到的链接所述,没有内置的 on-password-update 帐户触发器......只有 onCreate 和 onDelete 帐户触发器.这意味着我们必须手动处理它.我会以与您相同的方式处理它 - 使用云功能向用户发送电子邮件.

What you want is totally possible, but you'll have to implement it yourself. As the link you found states, there is no built-in on-password-update account trigger... only onCreate and onDelete account triggers. Which means we have to handle it manually. I would handle it the same way you are heading - using a cloud function to send the user an email.

我会构建一个名为 notifyUserOfPasswordChange()在您调用 .updatePassword().confirmPasswordReset() 的代码行之后立即从您的应用调用该云函数(.sendPasswordResetEmail() 之后的完成步骤).如果我理解您的问题的重点-这就是这里的真正答案.每当您执行密码更新代码时,您都需要手动调用云函数.没有自动触发器.

I would build a cloud function named something like notifyUserOfPasswordChange() and call that cloud function from your app immediately after the line of code where you call .updatePassword() or .confirmPasswordReset() (which is the finishing step after .sendPasswordResetEmail()). If I understand the point of your question - this is the real answer here. You will need to call a cloud function manually whenever you execute password update code. There's no automated trigger.

电子邮件可以像您编码一样简单或自定义.如果您不确定,那么从简单的开始,让云函数从 data 参数中获取目标电子邮件地址 - 然后为电子邮件正文使用通用消息.如果您觉得更有冒险精神,请考虑传递用户的 UID 并使用 Admin SDK 来查找该用户的注册电子邮件地址和显示名称,然后构建一个更漂亮的 &个性化 HTML 电子邮件.

The email can be as simple or customized as you code it. If you're unsure, then start simple and have the cloud function get the target email address from the data parameter - and then use a generic message for the email body. If you feel more adventurous, consider passing the user's UID and using the Admin SDK to look up that user's registered email address & display name and then building a prettier & personalized HTML email.

如何从 Firebase 云功能发送电子邮件而言,有很多示例 - 一个很好的示例在 Firebase 的 GitHub 页面上.

As far as how to send an email from Firebase cloud functions, there are plenty of examples out there - a good sample is on Firebase's GitHub page.

这篇关于如何在更改密码时触发 Firebase 中的云功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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