I'm trying to secure an app in which users can manage their bands. The users can be part of multiple bands and therefore can have different roles depending on which band they are in. The roles are stored in a Map Field in the Band document.
I currently have the following firebase/firestore rules setup:
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
match /bands/{bandID}{
function isBandAdmin(userID){
// Determine if user is a band admin
return get(/databases/$(database)/documents/bands/$(bandID)).data.members[userID].role == 'Admin';
}
allow read, update, create: if isSignedIn() && isBandAdmin(request.auth.uid);
// Rules for a band's concerts
match /events/{event}{
allow read, update, create: if isSignedIn() && (isBandAdmin(request.auth.uid));
}
}
}
Now this works perfectly if i perform a get request in the simulator provided by the firebase console. But in my project i'm trying to perform the following request:
database.collection("bands").where("name" ,"==", "AC/DC").get().then((docs) => {...});
This gives me a permission error. How can i make this work?
PS: I already posted a similar question but this is an important update.
firebase.auth().currentUser
right before running the query. - Frank van Puffelen