Hi I'm looking for help regarding some Firestore rules.
For some reason wildcards don't seem to work, or I'm doing something wrong...
Basically I'm trying to only allow 'read' permissions on a document collection if the companyId exists in their own user document.
So for example, I have a collection called "companies/16bc5ecc247a9".
In my user document I have a field of companyId: "16bc5ecc247a9".
So, If companyId: "16bc5ecc247a9" matches a collection inside another collection called 'companies' it'll grant permission
Here are the rules I'm using:
match /companies/{companyName} {
function comp() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.companyId == companyName;
}
allow read, write : if comp()
}
So as you can see I'm trying to say if the document name matches the value inside the user field allow
Here is a screenshot of my data
If it's needed, Here is all of my rules I'm using
I hope this make sense, Thanks in advance.