0
votes

Im trying to figure out how the rules in Firestore work, and have stumbled upon a problem I cant quite figure why is failing.

When using the Firestore Rules Playground and do a get request for a document in /apps, I get the following error: "Error running simulation — Error: simulator.rules line [10], column [14]. Null value error."

And from the app im getting: FirebaseError: Missing or insufficient permissions

The location in trying to get: "/apps/0aKQw0MiRzEbrLDvsnI3"

rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
  match /{document=**} {
    allow read, write: if isUserAuthenticated();
  }

  /* Functions */
  function isUserAuthenticated() {
    return request.auth.uid != null; 
  }
}

}

The thing im trying achieve is to allow read access for all document, and only write access if a user is signed in

I have no idea why it's failing on a get request?

1

1 Answers

0
votes

If I'm not mistaken the way you added the read condition seems to be incorrect. Perhaps try this and see if it works for you.

match /databases/{database}/documents { match /{document=**} { allow read: if true, write: if request.auth != null && request.auth.uid!=null }