service cloud.firestore {
match /databases/{database}/documents {
match /companies/{companyName=**}{
allow read,write: if isUserAuthorized(companyName,get(/databases/$(database)/documents/companies/$(companyName)/users/$(request.auth.uid)).data.company) == true;
}
}
}
function isUserAuthorized(requestedCompanyName,userCompanyName) {
return requestedCompanyName == userCompanyName;
}
In the above rule of firestore I am trying to make sure that only employees from a company can access data of that company. The data structure on firestore looks like the following screenshot. where data is saved in this path /companies/{companyName}/users/{uid}/company
But when I try to save I get Error: Missing or insufficient permissions. js error.
- Is there anything apparent I am doing wrong?
- Is there any logging that happens on firestore side where I can see what request was made and what were the values of variables used in the rules.
- Or is there a way to test the rules?
