问题描述
我想保留关于用户和玩家的特定规则,但我想要一个允许管理员用户无限制地编写的优先规则,它应该是“OR”,这意味着您要么是管理员,要么是规则如下。 (无需开始编辑下面的每个表格)
"rules": {
"scores": {
"$sid": {
".read": true,".write": "root.child('game').child($sid).child(auth.uid).exists()&&
auth!=null"
}
},...
解决方法
您可以为管理员用户添加更高级别的规则,例如,如果您通过 UID 识别管理员,您可以:
{
"rules": {
".write": "auth.uid === 'theuidofheadmin'","scores": {
"$sid": {
".read": true,".write": "root.child('game').child($sid).child(auth.uid).exists()&&
auth!=null"
}
},...
所以现在管理员对 root 下的任何东西都有写权限,你不能再把它们拿走,但其他人仍然需要满足每个特定节点的要求。
另见:
- How to only allow one admin user to write Firebase Database?
- Firebase security rules for admin read only even though they're set to false
- How to set up Firebase Realtime Database to allow developer to mark admins in the console
- firebase realtime db security rule to allow specific users
- Firebase Realtime Database rules to allow a single user Write access