Firebase注销显示权限被拒绝错误。 [英] Firebase logout show Permission denied error.

查看:234
本文介绍了Firebase注销显示权限被拒绝错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,无论何时我从Firebase注销,我都加上了

 错误:permission_denied:客户端没有权限访问所需数据。 

我知道这是因为登录会话被终止,我的一些对象不能再访问firebase数据。但是如何在注销之前断开这个对象呢?



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

  function logout(){
auth。$ unauth();
getCurrentUser();
};
函数getCurrentUser(){
var authData = auth。$ getAuth();
if(authData){
$ rootScope.userId = authData.uid;
$ rootScope.currentUser = $ firebaseObject(authRef.child(users)。child(authData.uid));
返回$ 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连接我没有关闭?另外,由于注销按钮在Profile范围内,其他连接是不同的范围,我不知道如何关闭连接,甚至不在配置文件范围内...

解决方案

您需要销毁所有firebase引用注销。
类似这样的。



在注销功能

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

在控制器中

  vm.profile = authService.profile(user.uid); // FirebaseObject参考
vm.parties = partyService.getPartiesByUser(user.uid); // firebaseArray参考
$ b $ root $ $ $($'$'$($'$'$'$'$'$' );
});


So whenever I logout from Firebase, I got coupled

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

I understand it is because login session is terminated, some of my objects cannot access firebase data any more. But how can I disconnect this objects before logout?

For logout button in one of my Ionic View, it just call a firebase service:

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...

解决方案

You need to destroy all the firebase references on logout. Something like this.

In logout function.

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

In controller

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();
});

这篇关于Firebase注销显示权限被拒绝错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆