验证Firebase密钥 [英] Validating a Firebase Key
本文介绍了验证Firebase密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{
rules:{
.write:true,
notifications:{
$年:{
.validate:newData.val()==='/ 15',
}
}
}
}
我正在模拟器中测试以下内容:
/ notifications / 15
p>
{foo:bar}
Firebase模拟器返回:
尝试写{foo:bar } to / notifications / 15 with auth = {provider:anonymous,uid:a5e08499-c41d-47d0-9df4-64d9af802755}
/:.write:true
=> true
/notifications/15:.validate:newData.val()==='/ 15'
=>假
验证失败。
写入被拒绝。
解决方案
$ c> / notifications / 15 然后 newData.val()
将是该值,而不是关键字。
我不认为有一种方法可以动态地测试键。
I am just getting started with Firebase security and probably I am missing something. I need to validate that after 'notification' the path(key) is 15 (later I will update 15 to be regex using matching method, but currently I am struggling enforcing this simple case):
{
"rules": {
".write": true,
"notifications": {
"$year": {
".validate": "newData.val() === '/15'",
}
}
}
}
I am testing in simulator with the following:
/notifications/15
Data I am posting:
{ "foo": "bar" }
The Firebase simulator returns:
Attempt to write {"foo":"bar"} to /notifications/15 with auth={"provider":"anonymous","uid":"a5e08499-c41d-47d0-9df4-64d9af802755"}
/:.write: "true"
=> true
/notifications/15:.validate: "newData.val() === '/15'"
=> false
Validation failed.
Write was denied.
解决方案
If you're writing a value to /notifications/15
then newData.val()
will be that value, not the key.
I don't think there is a way to test keys dynamically.
这篇关于验证Firebase密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文