Validating a Firebase Key [duplicate]

做~自己de王妃 提交于 2020-01-03 00:52:50

问题


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.

回答1:


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.



来源:https://stackoverflow.com/questions/32933181/validating-a-firebase-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!