验证Firebase密钥 [英] Validating a Firebase Key

查看:148
本文介绍了验证Firebase密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Firebase安全性,可能我缺少一些东西。我需要验证'通知'后,路径(键)是15(后来我会更新15是使用匹配方法的正则表达式,但目前我正在努力执行这个简单的情况):

  {
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆