2

I could really do with some help. I’m sort of stuck understanding how security rules and data structure works. Any help at all here would be amazing for me to understand and finally “get it”. I’m just not sure what I’m doing wrong!

This is the simplest example I can think of, but I still can’t get it to work... I just want to try and understand how all this fits together.

Firebase data structure Firebase security rules

So I have these collections and they are a flat structure where I have stored the user’s id (generated by Firebase) stored with the collection so I know which collection was made by which user.

But then, in my interface, I only want to show collections made by the logged in user. So I did a security rule like above, but it just doesn’t work.

I’m really stuck… I’ve followed tutorials and guides, but I just can’t get this to work at all! It returns nothing. Returning the collections rule to simply be ".read": true returns back all collections as expected.

Thanks for any help on this! Much appreciated!

James Morris
  • 255
  • 3
  • 7
  • I realise too, that I maybe doing this all wrong! Any suggestions on how better to structure my data would be appreciated too (if indeed what I have is not optimal). Thanks again for any help here! – James Morris May 06 '16 at 10:02
  • Are you sure that the user is authenticated? try to use ".read": "auth != null" to check it. – Gabriele Mariotti May 06 '16 at 10:25
  • You've included a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export button in your Firebase database. Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. – Frank van Puffelen May 06 '16 at 14:33
  • But aside from that, you're falling for one of the common pitfalls in Firebase's security rules. You cannot use security rules to filter data. See http://stackoverflow.com/a/14298525. – Frank van Puffelen May 06 '16 at 14:34

0 Answers0