Access to nested data for conditional with authenticated user

I am trying to make new message objects available only to users who exist in the member dictionary stored in each message. I keep getting the expression "7:17: Invalid ==: left operand is not a number, boolean, string or zero." in .read rule:

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

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

The goal is to allow reading messages only by users who exist in its member array. I cannot find examples of access to nested data in the documentation for firebase, google groups or Google search queries :-(

Allowed / possible?

+4
source share
1 answer

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

 ".read": "data.child('members').child(auth.uid).val() == true" 
+10
source

All Articles