0
votes

I need some help making my security rules for firestore work.

These are my firestore rules:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      function isAdmin(uid) {
        return (uid in get(/admin/administrators).data.uid)
      }
      allow read;
      allow write: if request.auth.uid != null && isAdmin(request.auth.uid);
    }
  }
}

In document /admin/administrators there is a field named uid containing an array of UIDs of administrators which are allowed to write in the database.

After I logged in as one such administrator and tried to add a document to another collection. (Specifically, the call in my Angular application using Angularfire 2 is this.afStore.collection(collection).add({});) I received the error Error: Missing or insufficient permissions.

Any help appreciated (including "there's obviously a better way to do this")

1

1 Answers

0
votes

You should enter the absolute path of the collection you're trying to reference. Change the (uid in get(/admin/administrators).data.uid) to get(/databases/$(database)/documents/admin/$(request.auth.uid)).data.uid