【发布时间】:2013-11-03 21:50:21
【问题描述】:
假设我为我的 Firebase 集合创建了一个新的 Email / Password 用户,名为 bob@example.com
我现在如何将对该集合中任何内容的写入权限限制为专门针对该用户?
{
"rules": {
".read": true,
".write": false
}
}
...?
【问题讨论】:
标签: firebase firebase-security
假设我为我的 Firebase 集合创建了一个新的 Email / Password 用户,名为 bob@example.com
我现在如何将对该集合中任何内容的写入权限限制为专门针对该用户?
{
"rules": {
".read": true,
".write": false
}
}
...?
【问题讨论】:
标签: firebase firebase-security
您可能需要更具体一些才能获得比security rules documentation 更有帮助的东西。但要回答您的问题,假设您想将整个 Firebase 写入权限限制为 Bob:
{
"rules": {
".read": true,
".write": "auth.email == 'bob@example.com'"
}
}
假设您想将 Firebase 中的 item 集合限制为 Bob:
{
"rules": {
".read": true,
"items": {
".write": "auth.email == 'bob@example.com'"
}
}
}
【讨论】:
auth 对象是rules 内可访问的范围,而items 是集合对象某些部分的句柄?如果你有 items.something.items 会发生什么? --- 或者假设本例中的items是从父节点开始的。
auth 在规则中可用; items 只是 Firebase 根目录下的一个示例父节点(只有 Bob 可以存储 item 对象)。 "rules" 将匹配从根开始的数据结构,因此如果 Bob 的数据位于 /items/something/items,您将拥有 "rules":{"items":{"something":{"items": "auth.email == "bob@example.com"}}}。无论如何,请浏览一下文档。