Firebase - 限制写入节点的安全规则 Owner/Creator
Firebase - Security Rule Restricting Write to Node Owner/Creator
在下面的屏幕截图中,我的 details
branch/node 包含许多使用随机 ID 命名的详细信息。如示例中所示,8641260c-900...
是一条详细记录,并且还会有其他几条这样的记录。
我想知道我的 .write
规则是否正确? 我想启用限制以便当前 auth.id
与现有规则完全匹配记录的 user
字段。
我还想限制删除记录(通过 .remove
)。
我可以简单地将 && !data.exists() || newData.exists()
添加到 .write
规则吗?
提前致谢。
I would like to know whether my .write rule is correct or not?
首先,将 ".read":true
和 ".write":true
赋予根节点将覆盖所有子节点规则 true
。因此,任何指定给子节点的规则都将变得多余。
I wanted to enable restriction so that current auth.id exactly match the existing record's user field.
{"rules":{
"existing_record":{
"user":{
".write":"newData.isString() && auth.uid == newData.val()"
}
}
}}
I would also wanted to restrict deletion of the record (via .remove).
newData.exists()
将阻止删除节点。 newData 表示数据在操作发生后的样子。因此,通过确保操作后newData存在,禁止删除节点。
在下面的屏幕截图中,我的 details
branch/node 包含许多使用随机 ID 命名的详细信息。如示例中所示,8641260c-900...
是一条详细记录,并且还会有其他几条这样的记录。
我想知道我的 .write
规则是否正确? 我想启用限制以便当前 auth.id
与现有规则完全匹配记录的 user
字段。
我还想限制删除记录(通过 .remove
)。
我可以简单地将 && !data.exists() || newData.exists()
添加到 .write
规则吗?
提前致谢。
I would like to know whether my .write rule is correct or not?
首先,将 ".read":true
和 ".write":true
赋予根节点将覆盖所有子节点规则 true
。因此,任何指定给子节点的规则都将变得多余。
I wanted to enable restriction so that current auth.id exactly match the existing record's user field.
{"rules":{
"existing_record":{
"user":{
".write":"newData.isString() && auth.uid == newData.val()"
}
}
}}
I would also wanted to restrict deletion of the record (via .remove).
newData.exists()
将阻止删除节点。 newData 表示数据在操作发生后的样子。因此,通过确保操作后newData存在,禁止删除节点。