You can definitely provide access to private and public data with your current data structure.
But one use case that you are likely to need at some point is to show a list of publicly available information for all users. With your current data structure, this is not possible because the Firebase Security Model cannot be used to filter data . To get an excellent answer, see Restricting access to child / fields using security rules .
Most developers split public and private data into completely separate subtrees:
{ "users" : { "YFIIAgwa2kaannrXjwvSZmoywma2" : { "Name:" : "Example 1", }, "YgSfSzPzxLbyDL17r6P9id2cdvH2" : { "Name:" : "Example 2", } }, "public_profiles": { "YFIIAgwa2kaannrXjwvSZmoywma2" : { "email" : " example1@gmail.com " }, "YgSfSzPzxLbyDL17r6P9id2cdvH2" : { "email" : " example2@gmail.com " } } }
Then you can protect access with
{ "rules": { "users": { "$uid":{ ".read": "auth != null && auth.uid == $uid", ".write": "auth != null && auth.uid == $uid", } }, "public_profiles": { ".read": "auth != null", "$uid":{ ".write": "auth != null && auth.uid == $uid", } } } }
Now any authenticated user can listen to /public_profiles , which means that you can easily show a list of these profiles.
source share