My app tries to read documents under the collection 'Sites'. I did a simulated read operation which works fine as is as follows:
Profile/'actual profile id'/Sites/'actual site id'
This simulated read works probably because I am reading a pre-defined document. I am not sure.
My security rule is as follows:
match /Profile/{profile}/Sites/{site} {
allow read: if isOneOfRoles (get(/databases/$(database)/documents/Profile/$(profile)/Sites/$(site)),['FULL', 'OWNER', 'VIEW']);
}
function getRole(rsc) {return rsc.data.SHARED_WITH[request.auth.token.email];}
function isOneOfRoles(rsc, array) {return isSignedIn() && (getRole(rsc) in array);}
And finally my query is as follows:
Firestore.instance.collection('Profile/${_firebaseUser.uid}/Sites')
.where('ARCHIVE',isEqualTo: false)
.orderBy('DATE',descending: true)
.getDocuments();
My database structure looks like the following:
I am getting permission denied error in my console. Need help in understanding where am I going wrong?