Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing nested data for conditional with authenticated user

Tags:

firebase

I'm trying to make new post objects readable only by users that exist in the 'members' dictionary stored in each post. I keep getting "7:17: Invalid == expression: left operand is not a number, boolean, string, or null." on the .read rule:

{
  "rules": {

  "posts" : {
      ".write":true,
      "$post" : {
         ".read": "data.child('members').child(auth.uid) == true"
      }
    }  
  }
}

I pass the 'uid' parameter in the token I generate per: https://www.firebase.com/docs/security/custom-login.html

The purpose is to only allow posts to be read by users that exist in its member array. I can't find any examples about accessing nested data in the firebase documentation, google groups, or google searches :-(

Is this allowed/possible?

like image 454
user2105753 Avatar asked Dec 11 '22 17:12

user2105753


1 Answers

You need to add .val() after .child() in order to get the value out. :-) Try:

".read": "data.child('members').child(auth.uid).val() == true"
like image 144
Michael Lehenbauer Avatar answered Jan 19 '23 01:01

Michael Lehenbauer