I'm having trouble querying a collection where the documents have differing permissions on them.
Is there anyway to perform a query on a collection to prevent getting permissions denied on documents I can't read. I'm able to achieve this if I query them one at a time.I need to query the collection to return multiple docs where I might not have permissions for some? I could keep a list of document Ids a specific user has access to query, but I can't find any documentation on specifying an array of documents.
Collection:
Library > { libraryID } > {
Users:{ uid, uid, uid },
title: 'Title of library'
}
Rules:
match /Library/{libraryID} {
allow read: if get(/databases/$(database)/documents/Library/$(libraryID)).data.Users[(request.auth.uid)] == true;
}
Permission are limited if the users id is in the data.
This works fine:
this.afs.collection<Library('Library').doc({libraryID}); // Everything works great
But I need multiple items from the collection, so when I try something like the example below if fails as I do not have permissions to all the documents in the collection:
this.afs.collection<Library('Library'); //PERMISSION DENIED
I was hoping I could use query to fix this, but because it is looking into the document it also fails:
this.afs.collection<Library('Library',ref => ref.where('Users/'+this._uid, '==', 'true')); // PERMISSION DENIED
So I wish I could just specify the docs I have access to ( this is what I need ) and return them in a collection
this.afs.collection<Library('Library').doc([{libraryID},{libraryID2},{libraryID3}])
If anyone knows a solution to achieve this, or a refactor of the structure to achieve this it would be a huge help.