【问题标题】:Logout with Firebase使用 Firebase 注销
【发布时间】:2015-04-27 00:21:37
【问题描述】:

我正在尝试进行用户身份验证,我现在正在注销

      <button ng-click="logOut(user)">
        GOING OUT
      </button>

这是他们的登录方式

  $scope.signIn = function (user) {
    $scope.signInErrorShow = false;
    if (user && user.email && user.pwdForLogin) {
      auth.$authWithPassword({
        email: user.email,
        password: user.pwdForLogin
      }).then(function (authData) {
        console.log("Logged in as:" + authData.password.email);
        ref.child("users").child(authData.uid).once('value', function (snapshot) {
          var val = snapshot.val();
          $scope.$apply(function () {
            $rootScope.displayName = val;
          });
        });
        $scope.userLogin = true;
        $ionicLoading.hide();
        $scope.closeModal();
        $rootScope.$broadcast('');
      }).catch(function (error) {
        $ionicLoading.hide();
      });
    } else
    $scope.signInErrorShow = true;
  };

我正在尝试调用 logOut

  $scope.logOut = function(user) {
    ref.unauth();
  };

一旦我调用注销,我就看不到任何帖子或进入浏览器的网络部分。

在 Firebase 文档中,他们所说的关于注销的只有这个

注销用户

调用 unauth() 会使用户的令牌无效并将其从您的应用程序中注销:

复制 ref.unauth(); 如果您之前使用 onAuth() 方法来侦听身份验证状态,那么现在将使用 null 为 authData 调用您的回调。

那我该怎么办呢?

【问题讨论】:

  • 我不明白问题出在哪里:一旦您致电unauth(),您就看不到任何新数据;这对我来说听起来像是预期的行为。您期待onAuth() 回调吗?您在问题中显示的代码未注册 onAuth() 回调,因此不会被调用。见:firebase.com/docs/web/api/firebase/onauth.html
  • 好的,我在做什么没关系?这就是我需要知道的。如果用户登录,我可以看到进入网络,但是一旦用户退出,我看不到网络中发生任何事情,所以我想知道如果用户退出网络,我该如何实现应用程序 ? @FrankvanPuffelen
  • 如果你想确定,注册一个onAuth处理程序。
  • 也可以在这里查看 Jacob 的最后评论:github.com/firebase/angularfire/issues/…

标签: angularjs firebase


【解决方案1】:

关于未显示任何网络活动的注销:登录时 firebase 可能会在您登录时为您提供访问令牌(由 firebase 客户端脚本保存)。

登录后,当您的应用程序访问 firebase 时,它​​会将此令牌添加到您的请求标头(授权标头?)。

当您注销时,firebase 客户端脚本只会删除令牌。这样,firebase 后端不必在其(分布式)服务器上保留会话状态。他们只需要检查每个请求中发送的令牌的有效性。

【讨论】:

  • 是的,经过一番研究,我意识到了这一点。非常感谢我的朋友。
猜你喜欢
  • 1970-01-01
  • 2020-08-30
  • 1970-01-01
  • 1970-01-01
  • 2021-07-30
  • 2018-10-23
  • 2018-11-30
  • 2019-01-27
  • 1970-01-01
相关资源
最近更新 更多