jan*_*nce 2 firebase firebase-security
我有这一套规则:
{
"rules": {
"facebook_users": {
"$user": {
".read": "$user == auth.id",
".write": "$user == auth.id",
"userData": {
"maxProjects": {
".validate": false
},
"userProjects": {
".validate": ???
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想让用户无法将子项添加到userProjects数组 if userProjects.length > userData.maxProjects。由于".validate": false规则,用户已经被拒绝写入 maxProjects 。如何将 userProjects 的长度与 maxProjects 进行比较?
如果不可能,那么正确的方法是什么?
您可以使用root特殊变量 withchild()来进行比较:
{
"rules": {
"facebook_users": {
"$user": {
".read": "$user == auth.id",
".write": "$user == auth.id",
"userData": {
"maxProjects": {
".validate": false
},
"userProjects": {
".validate": "data.val().length < root.child('facebook_users').child($user).child('userData/maxProjects').val()"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1885 次 |
| 最近记录: |