Firebase注销显示权限被拒绝错误。

时间:2015-06-10 02:27:26

标签: angularjs firebase angularfire firebase-authentication

因此,每当我从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();
          } 
        }
    };

所以我在那里销毁$ rootScope.currentUser。我为配置文件页面使用相同的getCurrentUser。因此错误没有以这种方式出现。但是在其他视图中,我有另一个$ firebaseArray,还有另一个Ref.on(“child_added”,函数(snap)与$ firebaseObject相同。当我查看配置文件页面时,此页面至少有3个firebase连接,当我退出时,我有3个permission_denied错误(注销按钮在用户个人资料页面上)。

我的问题是,在注销之前如何断开此firebase连接?有没有办法断开所有firebase连接 - 无论是AngularFire还是常规的Firebase?所以我可以注销而不用担心哪个firebase连接没有关闭呢?此外,由于Logout按钮位于Profile范围内,而其他连接位于不同的范围内,因此我不知道如何关闭甚至在配置文件范围内的连接......

3 个答案:

答案 0 :(得分: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();
});

答案 1 :(得分:0)

好吧,我想你有一个退出按钮。 所以在你的函数logout()中,你首先$销毁数据对象,不知何故等待(这是我试图找出的最佳实践),然后是authref.unauth(); 我说

答案 2 :(得分:-1)

您需要销毁之前保存数据的对象的firebase ref。怎么样?

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

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

this.songs $ ref.off();

使用此行,您的问题

相关问题