【发布时间】:2017-02-08 21:06:37
【问题描述】:
所以我正在使用 Firebase 制作日历应用程序,但遇到了一些问题。
我的数据库结构是这样的:
- calendar
- $year
- $month
- $day
- $uid
- name
- arrivalStatus
- users
- $uid
- name
- team
所以我想做的是,同一团队中的人必须能够阅读彼此在日历中的条目。我已经设置了这样的规则:
{
"rules": {
"users": {
"$uid": {
".read": "auth != null && auth.uid == $uid",
".write": "auth != null && auth.uid == $uid"
}
},
"calendar": {
"$year":{
"$month":{
"$day":{
"$uid":{
".read": "auth != null &&
root.child('users/'+auth.uid+'/team').exists() &&
root.child('users/'+$uid+'/team').val() == root.child('users/'+auth.uid+'/team').val()",
".write": "auth != null && auth.uid == $uid"
}
}
}
}
}
}
}
但无论出于何种原因,在通过模拟运行时,无论您在哪个团队,请求都会被批准。我错过了什么明显的东西吗?
编辑:
所以基本上让我们假设这个数据集:
-firecalender
-calendar
-2016
-9
-30
-gsdfgd
-Name: "MG"
-Status:"PM"
-users
-abcd
-name: "Tester"
-team: "bc"
-efg
-name: "noteam"
-team: "funny inc"
-gsdfgd
-name: "bossman"
-team : "bc"
在这种情况下,abcd 应该能够读取日历中每个 gsdfgd 的信息,但应该拒绝 efg 访问。
【问题讨论】:
-
您是否尝试过在安全规则中更改 $uid 的名称。现在你在两个地方使用 $uid,也许 firebase 看不出区别。
-
您能否展示您希望失败的操作(包含确切的路径、数据和活动 uid)以及它成功的基础数据?
-
如果 UID 为 abcd 或 gsdfgd,则应允许基本 calendar/2016/9/30/gsdfgd/,但如果 UID 为 efg,则应拒绝
标签: firebase firebase-realtime-database firebase-security