I have a cloud firestore. In this store I have a collections of all admins. All data from the store can be read by anyone, but writes should be limited to the admins. If someone tries to write to a collection, e.g. latest-news, I want to see if the user that tries to write to the collection is an admin. The idea I want is something like this:
match /latest-news/{news-id} {
allow read: if true;
allow write: if <my-admin-collection>.map(auth => auth.uid).includes(request.auth.uid);
}
How would I actually do this?
If your collection of admins stores those admins by their UID, you can check for the existence of such a document from your rules with:
The above allows the operation if a document with the current user's UID exists in the
/admins
collection.Also see the documentation on attribute-based and role-based access control.