Firebase是否可以退出平台Web和移动应用程序?

时间:2018-11-15 10:32:28

标签: firebase firebase-authentication

我可以让用户同时注销Web应用程序和移动应用程序,以便从Web应用程序注销后不再能够登录到移动应用程序吗?

1 个答案:

答案 0 :(得分:3)

无法在其他设备上注销某人,但是您有几种选择,只需将一些元素放在一起。

您可以revoke the users refresh tokens,这意味着令牌过期且SDK刷新时无法刷新,并会注销用户。

// Revoke all refresh tokens for a specified user for whatever reason.
// Retrieve the timestamp of the revocation, in seconds since the epoch.
admin.auth().revokeRefreshTokens(uid)
    .then(() => {
      return admin.auth().getUser(uid);
    })
    .then((userRecord) => {
      return new Date(userRecord.tokensValidAfterTime).getTime() / 1000;
    })
    .then((timestamp) => {
      console.log("Tokens revoked at: ", timestamp);
  });

您还可以在Firebase实时数据库中放置一个标志,然后当他们在其他设备上重新打开该应用程序时,如果登录,他们可以读取该标志并在客户端上注销。另外,如果他们打开了网络/移动应用程序,并且他们一直在收听该标志,则可以通过这种方式注销他们。

var logoutRef = firebase.database().ref('userLogoutRef/' + userUid);
logoutRef.on('value', function(snapshot) {
  if (snapshot.val() === true) {
      firebase.auth().signOut()
  }
});

您只想确保在以后的登录时删除此标志,以便用户可以登录。