【问题标题】:Event triggered when changing a user Firebase Authentication更改用户 Firebase 身份验证时触发的事件
【发布时间】:2019-01-10 02:31:26
【问题描述】:

检测来自用户 Firebase 身份验证的事件

在我使用 Angular 以及 Node.jsFirebase 开发的应用程序中,我需要检测用户中发生的事件。作为包容、改变和排斥。

有没有办法通过Cloud Functions中创建的函数来检测用户何时被删除、更改或插入?

我知道您可以使用在 Cloud Functions 中创建的函数来检测数据库事件。当通过Firebase Console > Project > Authentication完成操作时,我想检测用户何时被更改、删除或输入。

某种意义上的东西:

exports.userChanged = functions.user
  .onCreate((snapshot, context) => {})

OnDelete()
OnCreate()
OnChange()

最好的方法是什么?

【问题讨论】:

  • 我不清楚你在问什么。你能缩小问题的范围吗?例如。如果您想知道在更新用户个人资料时是否可以触发云功能,请将您的问题限制在此范围内。答案是不可能的:stackoverflow.com/questions/47933827/…
  • 缩小了问题的范围。我需要做的是在插入/更改或删除用户时检测事件。与我使用 Cloud Functions 创建函数以检测实时数据库中的事件时发生的方式相同。

标签: javascript angular firebase firebase-authentication google-cloud-functions


【解决方案1】:

onCreateonDelete,你可以从docs读到。

对于更新案例,您应该依赖 RTD。实际上,您可以完全依赖 RTD。

//Create a user on the rtd
functions.auth.user().onCreate((user) => {
    return usersRef.child(user.uid).set(user);
});

//Update the user by listening to a change on the RTD
functions.database.ref('/users/{uid}')
    .onWrite((change, context) => {
         //If you needed it you can update the user
         admin.auth().updateUser(uid, {
         });

         //if some condition, then delete it
         admin.auth().deleteUser(uid)

         //do more
    }); 

使用更新用户选项,您甚至可以禁用该帐户,看看这个other answer

你可以直接使用Functions里面的admin sdk,这是doc

【讨论】:

    猜你喜欢
    • 2014-12-25
    • 2021-08-01
    • 2016-11-15
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    相关资源
    最近更新 更多