【发布时间】:2015-08-25 02:23:21
【问题描述】:
所以每当我从 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", function(snap) 具有相同的 $firebaseObject。当我查看个人资料页面时,此页面至少有 3 个 firebase 连接, 注销时出现 3 个 permission_denied 错误(注销按钮位于用户个人资料页面上)。
我的问题是,我如何在注销之前断开此 Firebase 连接?有没有办法断开所有的 Firebase 连接——无论是 AngularFire 还是普通的 Firebase?所以我可以注销而不用担心我还没有关闭哪个firebase连接?另外,由于注销按钮在配置文件范围内,而其他连接在不同的范围内,我不知道如何关闭甚至不在配置文件范围内的连接......
【问题讨论】:
-
你在用“$onAuth”做什么吗?也许在你的认证工厂?
-
是的,我愿意。但是使用 onAuth 仍然不知道注销时应该关闭什么。因为我的实例无处不在。他们中的大多数在离开视图时我无法关闭,因为他们都需要收听来自 firebase 的更新。
标签: angularjs firebase angularfire firebase-authentication