I have a users and friends collection in Firebase structured as follows:
Users:
UID-1
Email
Username
UID-2
Email
Username
...
Friends:
FID-1
UID-1
UID-2
...
Where usernames are public but emails are private, as enforced by current rules. I want to be able to retrieve a list of the UIDs that a user is friends with securely.
I found it simple enough to enforce username and email access by specifying auth != null or auth.uid == $UID but how do I go about making it so that users can only access the Users documents that they are friends with?
Can I query the database 'internally' as part of a rule? I.e. "Only allow retrieval of this document if the user is friends with them (friend information stored at "Friends" directory)?" I am okay if the solution posed requires restructuring the data or the existing security rules.