I have the following rule set for events:
"events": {
".indexOn": ["startTime"],
"$eventId" : {
".read": "auth != null && data.child($eventId+'/startTime').val() < (now + 86400000)",
".write": "auth != null && data.exists() && auth.uid === data.child('uid').val() || auth != null && root.child('proUsers/'+auth.uid).exists()"
}
}
My intention was to limit read for all events to events that have startTime less than tomorrow. Thus I set a listener using .on() with "value like so:
database.ref('events').orderByChild('startTime').on('value', (snapshot) => { console.log(snapshot.val())}
however I get nothing, error occurs. Whats wrong with my rule. I did not want to set the ".read": "auth != null"
right below events since rules cascade.
Update: According to Restricting child/field access with security rules, I need to store a separate list of all approved to view events and set a read rule on that, but the problem is that in my case approved list changes according to the startTime value, thus it needs to happen automatically thus that solution does not work for me.