我有火力地堡数据结构有点像这样:火力地堡安全规则 - 允许读取仅用于用户的内容
+ tasks
+ task_id
+ title
+ user
+ ...
+ users
+ ...
的从前端(使用AngularJS和AngularFire(加上内置的SimpleLogin)) - 当登录用户创建任务时,用户的uid(例如simplelogin:2)被放入正在创建的任务的用户部分。
当用户登录时,他们可以通过使用只查看他们的任务:
$firebase(ref.orderByChild('user').equalTo(User.uid));
下一步是保护数据,这就是我挣扎。我已经试过:
"tasks": {
".indexOn": ["user", "order"],
".write": "auth != null",
".read": "auth != null && data.child('user').val() == auth.uid",
"$task": {
"title": {
".validate": "newData.isString() && newData.val().length <= 1000"
},
"completed": {
},
"time_added": {
".validate": "newData.val() <= now"
},
"order": {
},
"user": {
".validate": "newData.val() != null && newData.val() == auth.uid"
},
"$other": {
".validate": false
}
}
}
也:
"tasks": {
"$task": {
".indexOn": ["user", "order"],
".write": "auth != null",
".read": "auth != null && data.child('user').val() == auth.uid",
"title": {
".validate": "newData.isString() && newData.val().length <= 1000"
},
"completed": {
},
"time_added": {
".validate": "newData.val() <= now"
},
"order": {
},
"user": {
".validate": "newData.val() != null && newData.val() == auth.uid"
},
"$other": {
".validate": false
}
}
}
但是我得到:
Error: permission_denied: Client doesn't have permission to access the desired data.
我要去哪里错了?
不能使用安全规则的过滤器。这包括使用查询。由于查询必须从本质上读取任务/以获取匹配的子项,因此查询失败是因为在父级(即迭代)级别上不允许读取访问。 – Kato 2015-01-27 20:57:48
Hi @Kato - 在这种情况下,你的建议是什么?所有任务只能在'user'字段中被用户(1个或多个)访问。还是我错误地构造数据? – mcnamee 2015-01-28 08:20:19
查看[结构化数据](https://www.firebase.com/docs/web/guide/structuring-data.html)指南。有一个标题为创建涵盖指数的数据的部分。这里有一些变体是必要的。 – Kato 2015-01-28 16:12:23