In Firestore I have a collection of items with an owner.
The owner can be a user, who should be allowed to read his documents.
With a userId
you could do like this:
allow read, write: if resource.data.userId == request.auth.uid;
But with an owner
reference field there is seemingly no documentation when it comes to security rules.
I tried this security rule:
allow read, write: if resource.data.owner == 'users/$(request.auth.uid)';
and querying like this:
const owner = this.db.collection('/users').doc(auth.uid).ref;
const collection = this.db.collection('/items',
(ref) => ref.where('owner', '==', owner)
);
but I'm still getting Missing or insufficient permissions.