Firebase规则-嵌套的if



我想做一些嵌套的if语句,以实现每个用户的电子邮件在获得读写访问权限之前都经过验证。但我不知道该怎么做,因为如果我用写的话

"rules" : {
"read" : "auth.token.email_verified",
"write" : "auth.token.email_verified"
"other_location" :{
"read" : true, 
"write": false
}
}

即使我在other_location中将write设置为false,用户也会在other_location中获得write。我不知道为什么会这样,但我的模拟显示了这一点。有人能帮我吗?

Firebase RTDB规则从更高层级联到更具体的层。如果您允许对给定的键执行读/写操作,在您的情况下,该键是数据库的根,则嵌套在该键下的任何键都将共享相同的允许读/写权限,即使嵌套规则另有规定。

为了克服这一问题,可以使用键路径中的变量来匹配未命名的位置。按照惯例,这些"其他键"变量称为"$other"

{
"rules": {
"restricted-location": {
".read": true,
".write": false
},
"$other": { // any key not named above at this level  
".read": "auth.token.email_verified",
".write": "auth.token.email_verified"
}
}
}

最新更新