如何在不分离每个字段的情况下创建 Firebase 表......为了安全?
How to create Firebase tables without separating every single field...for security?
所以我正在研究 Firebase 安全规则,据我所知,在树中更高层级指定的规则进一步向下层叠到树中。
所以我想知道是否有一种方法可以让我基本上有一个 /bands
子树,我希望任何人都可以写它,但是有 admins
和 members
根据特殊条件,我只希望可写的子树。
到目前为止,这就是我正在进行的事情:
{
"rules": {
".read": "auth != null",
"bands": {
"$bandId": {
".write": "auth !== null",
"$bandId": {
".write": "auth !== null && data.child('creator_id').val() === auth.uid"
}
}
}
}
}
当我去测试 "writing" 时,在 Firebase 模拟器中,类似 /bands/-KnLeIHM4zCspwBZjZP9
的东西 creator_id
与我提供的指定 auth.uid
不匹配,我由于 /bands
树级别具有写入权限,因此仍然获得模拟器写入成功。
有什么聪明的方法可以让任何人从 "push" 到 /bands
但是当它下降到实际的 /bands/$bandId
级别时,它会开始查看这些不同的条件?还是我将不得不重新处理我的数据并将树分成更多的树?我还有其他情况需要这种事情,但这是我正在使用的最简洁的版本,我需要解决。
有什么想法吗?提前致谢:)
{
"rules": {
"bands": {
".read": "auth != null",
".write": "!data.exists() && auth != null",
"$bandId": {
".write": "data.child('creator_id').val() === auth.uid"
}
}
}
}
".write": "!data.exists() && auth != null"
将只允许经过身份验证的用户写入 bands
内的路径,如果它们不存在(创建新内容)。
所以我正在研究 Firebase 安全规则,据我所知,在树中更高层级指定的规则进一步向下层叠到树中。
所以我想知道是否有一种方法可以让我基本上有一个 /bands
子树,我希望任何人都可以写它,但是有 admins
和 members
根据特殊条件,我只希望可写的子树。
到目前为止,这就是我正在进行的事情:
{
"rules": {
".read": "auth != null",
"bands": {
"$bandId": {
".write": "auth !== null",
"$bandId": {
".write": "auth !== null && data.child('creator_id').val() === auth.uid"
}
}
}
}
}
当我去测试 "writing" 时,在 Firebase 模拟器中,类似 /bands/-KnLeIHM4zCspwBZjZP9
的东西 creator_id
与我提供的指定 auth.uid
不匹配,我由于 /bands
树级别具有写入权限,因此仍然获得模拟器写入成功。
有什么聪明的方法可以让任何人从 "push" 到 /bands
但是当它下降到实际的 /bands/$bandId
级别时,它会开始查看这些不同的条件?还是我将不得不重新处理我的数据并将树分成更多的树?我还有其他情况需要这种事情,但这是我正在使用的最简洁的版本,我需要解决。
有什么想法吗?提前致谢:)
{
"rules": {
"bands": {
".read": "auth != null",
".write": "!data.exists() && auth != null",
"$bandId": {
".write": "data.child('creator_id').val() === auth.uid"
}
}
}
}
".write": "!data.exists() && auth != null"
将只允许经过身份验证的用户写入 bands
内的路径,如果它们不存在(创建新内容)。