Tho*_*hoe 7 firebase google-cloud-functions
我看到如何在用户帐户创建时执行云功能:
exports.myFunction = functions.auth.user().onCreate(event => {
Run Code Online (Sandbox Code Playgroud)
但是我需要在用户登录时执行我的函数。有onLogin触发器吗?
有 1500 分的人可以创建一个标签firebase-cloud-functions吗?
没有登录事件,因为只有客户端可以准确定义登录发生的时间。不同的客户可能会以不同的方式对此进行定义。如果您需要在登录时触发某些内容,请确定该点何时在您的应用程序中,然后通过数据库或 HTTP 函数从客户端触发它。
这在控制器中起作用:
firebase.auth().onAuthStateChanged(function(user) { // this runs on login
if (user) { // user is signed in
console.log("User signed in!");
$scope.authData = user;
firebase.database().ref('userLoginEvent').update({'user': user.uid}); // update Firebase database to trigger Cloud Function
} // end if user is signed in
else { // User is signed out
console.log("User signed out.");
}
}); // end onAuthStateChanged
Run Code Online (Sandbox Code Playgroud)
这是 Cloud Function 中的触发器:
exports.getWatsonToken = functions.database.ref('userLoginEvent').onUpdate(event => { // authentication trigger when user logs in
Run Code Online (Sandbox Code Playgroud)
我在 Firebase 数据库中创建了一个名为userLoginEvent.
一个令人困惑的地方是,在函数控制台中,它是/userLoginEvent但在您的代码中,您必须省略斜线。

| 归档时间: |
|
| 查看次数: |
6398 次 |
| 最近记录: |