Firebase 规则权限被拒绝,但为什么呢?
Firebase Rules permission denied but why?
这是我的规则:
{
"rules": {
"freecoinsrequest":{
".read": false,
".write": "
newData.child('uid').val() == auth.uid
1. && (root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').val() < now - 10000
2. || !root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').exists())
" ,
"uid":{
".validate" : true
},
"$other":{
".write": false,
".validate": false
}
},
}
}
因此用户应该只能在以下情况下写入路径:
- JSON 包含 "uid" 作为键,他的 uid 作为值
- 他没有在 10 秒前写信给 server/lasttimetookfreecoins 或者
- 他从未写信给server/lasttimetookfreecoins
我不明白为什么它在模拟器中被拒绝。当我取消注释 1 和 2 时,如规则所示,它起作用了。
谢谢。
在我的测试中,规则在 /users/$uid/server/lasttimetookfreecoins
存在时产生了预期的结果,但在不存在时失败了。颠倒条件的顺序固定为:
newData.child('uid').val() == auth.uid
&& (!root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').exists()
|| root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').val() < now - 10000)
这是我的规则:
{
"rules": {
"freecoinsrequest":{
".read": false,
".write": "
newData.child('uid').val() == auth.uid
1. && (root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').val() < now - 10000
2. || !root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').exists())
" ,
"uid":{
".validate" : true
},
"$other":{
".write": false,
".validate": false
}
},
}
}
因此用户应该只能在以下情况下写入路径:
- JSON 包含 "uid" 作为键,他的 uid 作为值
- 他没有在 10 秒前写信给 server/lasttimetookfreecoins 或者
- 他从未写信给server/lasttimetookfreecoins
我不明白为什么它在模拟器中被拒绝。当我取消注释 1 和 2 时,如规则所示,它起作用了。
谢谢。
在我的测试中,规则在 /users/$uid/server/lasttimetookfreecoins
存在时产生了预期的结果,但在不存在时失败了。颠倒条件的顺序固定为:
newData.child('uid').val() == auth.uid
&& (!root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').exists()
|| root.child('users').child(auth.uid).child('/server/lasttimetookfreecoins').val() < now - 10000)