更改用户Firebase身份验证时触发的事件

时间:2018-08-02 10:41:26

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

从用户Firebase身份验证中检测事件

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

是否有办法检测通过Cloud Functions中创建的功能删除,更改或插入用户的时间?

我知道您可以使用Cloud Functions中创建的功能检测数据库事件。我想检测通过 Firebase控制台>项目>身份验证完成操作时何时更改,删除或输入用户。

这种含义:

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

OnDelete()
OnCreate()
OnChange()

做到这一点的最佳方法是什么?

1 个答案:

答案 0 :(得分:0)

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

您可以直接在Function内部使用admin sdk,这是doc

相关问题