这是我在firebase上的模型:
Texts
-KAa-aU_RjZwM7FLQcWt
id: "5f9fe424-4323-4370-a280-9cb216dc6410"
text: "gregegreg"
-KAa-bZC2ouIRQ54YWWr
id: "5f9fe424-4323-4370-a280-9cb216dc6410"
text: "gregegreg"
这些是我的规则:
"rules": {
"Texts": {
".read": "auth.id === data.child('id').val()",
".write": true
}
}
不幸的是,当我使用另一个UID而不是5f9fe424-4323-4370-a280-9cb216dc6410
时,我仍然可以阅读我的所有模型文本任何想法谢谢你!
验证部分适用于angularJs和login-password:
var firebaseObj = new Firebase("https://blinding-heat-xxxx.firebaseio.com");
$scope.authObj = $firebaseAuth(firebaseObj);
$scope.login = function() {
$scope.authData = null;
$scope.error = null;
$scope.authObj.$authWithPassword({
email: $scope.email,
password: $scope.password
}).then(function(authData) {
console.log("Logged with id:", authData.uid);
$scope.loadData();
}).catch(function(error) {
console.error("Auth Failed :", error);
$scope.error = error;
});
};
最终将数据加载到网页上:
$scope.loadData = function(){
var ref = new Firebase("https://blinding-heat-xxxx.firebaseio.com");
$scope.Texts = $firebaseArray(ref.child('Texts'));
}
在HTML中,angularJs就在那里:
<div ng-repeat="text in Texts">text.text</div>
真正奇怪的是,以下规则非常有效,例如:
"rules": {
"Texts": {
".read": " auth != null ",
".write": true
}
}