Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Firebase注销显示拒绝权限错误。_Angularjs_Firebase_Angularfire_Firebase Authentication - Fatal编程技术网

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

Angularjs Firebase注销显示拒绝权限错误。,angularjs,firebase,angularfire,firebase-authentication,Angularjs,Firebase,Angularfire,Firebase Authentication,所以,每当我从Firebase注销时,我都会被耦合 Error: permission_denied: Client doesn't have permission to access the desired data. 我理解这是因为登录会话被终止,我的一些对象无法再访问firebase数据。但是在注销之前如何断开这些对象的连接 对于Ionic视图中的注销按钮,它只需调用firebase服务: function logout() { auth.$unauth(); g

所以,每当我从Firebase注销时,我都会被耦合

Error: permission_denied: Client doesn't have permission to access the desired data.
我理解这是因为登录会话被终止,我的一些对象无法再访问firebase数据。但是在注销之前如何断开这些对象的连接

对于Ionic视图中的注销按钮,它只需调用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_”),函数(snap)和同一个$firebaseObject。当我查看配置文件页面,然后查看至少有3个firebase连接的页面时,我在注销(注销按钮在用户配置文件页面上)时收到了3个被拒绝的权限错误


我的问题是,我如何在注销之前断开这个firebase连接?有没有办法断开所有firebase连接?无论是AngularFire还是常规firebase?这样我就可以注销而不必担心我还没有关闭哪个firebase连接?另外,因为注销按钮在配置文件范围内,而其他连接在di中不同的范围,我不知道如何关闭不在配置文件范围内的连接…

好吧,我想你有一个注销按钮。 因此,在函数logout()中,首先$destroy数据对象,以某种方式等待(这是我试图找出的最佳实践),然后authref.unauth();
我想说,你需要在注销时销毁所有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();
});

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

之前,我初始化我的var歌曲,如下所示: this.songs=this.af.list('/songs')

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

此.songs.$ref.off()


有了这一行,您的问题

您是否在使用“$onAuth”进行任何操作?可能在您的auth工厂?是的,我知道。但是使用onAuth仍然不知道注销时应该关闭什么。因为我的实例无处不在。大多数实例在离开视图时我都无法关闭,因为它们都需要收听firebase的更新。这可能是一个解决方案。但是使用$rootscope似乎有点不方便。使用$rootscope可以广播徽标ut事件。如果销毁firebase引用,则需要某种方法重新初始化定义引用的工厂/服务/控制器。如果不这样做,则注销并重新登录后将不会有任何数据。所有-我遇到了相同的问题,快速修复方法是更新规则{.read::true},仅用于读取访问,有些类似的帖子您可以通过简单的方式解决此问题。还有一些示例可以通过编写装饰程序并销毁使用$firebaseArray和$firebaseObject创建的所有firebase引用来解决此问题。