9

因此,每当我从 Firebase 注销时,我都会被耦合

Error: permission_denied: Client doesn't have permission to access the desired data.

我知道这是因为登录会话已终止,我的某些对象无法再访问 firebase 数据。但是如何在注销之前断开这些对象?

对于我的一个 Ionic View 中的注销按钮,它只调用一个 firebase 服务:

function logout() {
      auth.$unauth();
      getCurrentUser();
};
function getCurrentUser() {
        var authData = auth.$getAuth();
        if (authData) {
            $rootScope.userId = authData.uid;
            $rootScope.currentUser = $firebaseObject(authRef.child("users").child(authData.uid));
            return $rootScope.currentUser;
        } else {
          console.log("User is not login!");
          $rootScope.userId = null;
          $location.path("/auth/signin");
          if ($rootScope.currentUser) {
            $rootScope.currentUser.$destroy();
          } 
        }
    };

So I destroy the $rootScope.currentUser there. I use the same getCurrentUser for profile page. So the Error did not show up this way. But when in other views, which I have another $firebaseArray, and also another Ref.on("child_added", function(snap) with the same $firebaseObject. When I view the profile page, then this page with at least 3 firebase connection, I got 3 permission_denied Errors when I logout (logout button is on user profile page).

My question is, how do I disconnect this firebase connection before I logout? Is there a way disconnect ALL the firebase connection - no matter AngularFire or regular Firebase? So I can logout without worry about which firebase connection I have no close yet? Also, since the Logout button is in Profile scope and the others connection is in a different scope, I have no idea how to close the connection which is not even in the profile scope...

4

3 回答 3

2

您需要在注销时销毁所有 firebase 引用。像这样的东西。

在注销功能中。

function logout() {
       auth.$unauth();
       $rootScope.$broadcast('logout');
};

在控制器中

vm.profile = authService.profile(user.uid); // FirebaseObject Reference
vm.parties = partyService.getPartiesByUser(user.uid); // FirebaseArray Reference

$rootScope.$on('logout', function () {
  vm.parties.$destroy();
  vm.profile.$destroy();
});
于 2016-01-30T06:10:04.800 回答
0

好吧,我猜你有一个退出按钮。所以在你的函数 logout() 你首先 $destroy 数据对象,以某种方式等待(这是我试图弄清楚的最佳实践),然后是 authref.unauth(); 我会说

于 2015-08-05T21:44:09.000 回答
-1

您需要销毁之前保存数据的对象的 firebase ref。如何?

之前,我像这样初始化我的 var 歌曲: this.songs = this.af.list('/songs');

当我 signOut() 时,我应该销毁我初始化的变量的引用,以便我执行:

this.songs.$ref.off();

有了这条线,你的问题

于 2017-06-13T19:14:25.517 回答