使用Firebase RuleDataSnapshot方法访问用户数据

时间:2015-10-12 18:20:06

标签: firebase firebase-security

如果我有这样的数据:

        root{
           PrivateRooms{
             <PrivateRoomName>{
               ...
             }
           }
           users{
             <uid>{
               permissionFrom{
                   <PrivateRoomName>:value is not private room name 
               }
                ...
             }
           }
         }

...如何编写规则以授予对&lt;的访问权限? PrivateRoomName&gt;根据用户的许可从孩子那里获得?

我认为这样可行:

{
  "rules": {
    "PrivateRooms" : {
      "$roomName":{
        ".read" : "root.child('users').child(auth.uid).child('permissionFrom').hasChild('$roomName') == true",
        ".write" : "root.child('users').child(auth.uid).child('permissionFrom').hasChild('$roomName') == true"
      }
    },
    "users" : {
      ".read" : true,
      ".write" : true
    }
  }
}

...但是规则必须出错,因为跳过了这个数据快照:

var testRef = new Firebase('https://my.firebaseio.com/privateRooms/<privateRoomName>/privRoomChild');
testRef.once("value", function(snapshot){
    var testVal = snapshot.val();
    console.log(testVal);
});

1 个答案:

答案 0 :(得分:3)

在您的规则中,address_code是一个变量,因此不应该用引号括起来。

description