安全规则:
{
"rules": {
"chats": {
"$org": {
".read": "auth != null",
".write": "auth.org == $org"
}
}
}
}
服务:
"$$fbase": ['$timeout', function($timeout) {
return {
...
ref: function(path) { var self = this;
var ref = new Firebase(self.url + path);
self.ready = false;
ref.auth(self.auth_token, function(err) {
if (!err) {
if (console) console.log(path+" login succeeded.");
$timeout(function() { self.ready = true; });
}
});
return ref;
},
bind: function(ref, excludes, limit, start) { var self = this;
var result = {total: 0, list: []};
ref.on('value', function(data) { result.total = data.numChildren(); });
return result;
},
}
}],
控制器:
QuickMsgCtrl: ['$scope', '$$fbase', '$timeout',
function($scope, $$fbase, $timeout) {
var ref = $$fbase.ref("/chats/abc");
$scope.$watch(function() { return $$fbase.ready }, function() {
if ($$fbase.ready) {
var data = $$fbase.bind(ref);
$scope.listing = data.list;
}
});
}],
Chrome控制台:
/chats/abc login succeeded.
FIREBASE WARNING: on() or once() for /chats/abc failed: permission_denied
此时我很清楚,尽管登录成功,但是你身边的一个错误是允许我进行简单阅读。
不,AngularFire对我来说毫无用处,因为它没有做过身份验证,而且它有很多错误。