代码之家  ›  专栏  ›  技术社区  ›  Daibaku

Firebase是否有办法同时注销平台web和移动应用程序?

  •  0
  • Daibaku  · 技术社区  · 7 年前

    我可以让用户同时注销web和移动应用程序吗?这样一旦从web应用程序注销,就不能再登录移动应用程序了?

    1 回复  |  直到 7 年前
        1
  •  3
  •   Jack Woodward    7 年前

    没有办法在不同的设备上注销某人,但您有几个选项,只需要将一些元素放在一起。

    你可以 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);
      });
    

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

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