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

查看:50
本文介绍了如何在密码更改后在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).

我发现了一个类似的问题,但是它只询问有关密码更改的触发器,并且没有有关解决方法的信息:

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?

推荐答案

您想要的东西完全可以实现,但是您必须自己实现.如您所找到的链接所述,没有内置的密码更新帐户触发器...仅

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.

电子邮件可以像您编写代码时一样简单或自定义.如果不确定,则从简单开始,并使用cloud函数从 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云功能发送电子邮件,这里有很多示例-

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天全站免登陆