0

I have been struggling for days now trying to get my Firestore security rules to work with basic rules - even ones copied and pasted from the docs. I have tried to spin up the development and test emulator, but it failed due to what appears to be npm conflicts.

I tried to use the rules playground, but it gives me the error that the "get" function is not recognized. I found that this problem has occurred in the past. I could really use some help in figuring out where to start with this. I am considering abandoning the firestore system all together as along with these problems, the system frequently fails to connect.

enter image description here

The full get statement is ...

get(/databases/$(database)/documents/users/$(request.auth.uid)).data.designer ==true

I have tried a number of variations of this with no success.

If this is a problem with the tester, how can I test my queries and figure out where the problems lie. If this is a bigger problem, what do I do?

Update : The read will work if I am querying the users collection as in the query below.

allow read : if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.designer == true

The issue seems to lie in when I need to retrieve docs without knowing the specific ID of the doc in question - getting multiple docs based upon the security rule.

Joshua Foxworth
  • 1,236
  • 1
  • 22
  • 50

1 Answers1

0

You are testing without a signed in user, which means that the $(request.auth.uid) expression inside your call to get() fails. To make this work you'll need a signed in user.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I have tried this and the get fails on that as well. Using resource.data.designerId fails as well – Joshua Foxworth May 18 '20 at 05:20
  • The fact that no user is signed in is definitely the cause of the error in your screenshot. I reproduced it, and then fixed it by enabling authentication in the Rules Playground. If you have another problem in there after fixing this one, show the updates state in your question. – Frank van Puffelen May 18 '20 at 13:25
  • So, why does something like "if resource.data.designerId == request.auth.uid" always return a null for resource? – Joshua Foxworth May 18 '20 at 14:24