这是我在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
}}
发布于 2016-02-16 02:21:07
就快到了!它实际上是auth.uid,而不是auth.id。
此外,您还需要提供一个通配符,即一个$变量,用于将规则应用于/Texts下的任何子级。
"rules": {
"Texts": {
"$text_id": {
".read": "auth.uid === data.child('id').val()",
".write": true
}
}
}如果不使用通配符,该规则将应用于/Texts的静态路径。
这是模拟器中的输出。

https://stackoverflow.com/questions/35416245
复制相似问题