I am trying to get all posts made between two users to each other in one firestore query, but I get permission denied. I have a "posts" collection with post documents that have the following fields:
{
to : uid_of_user_receiving_post,
from : uid_of_user_sending_post,
queryIdentifier: uidsToQueryIdentifier(uid_of_user_receiving_post, uid_of_user_sending_post),
...
}
where:
uidsToQueryIdentifier = (uid1, uid2) => {
if (uid1 < uid2) {
return uid1 + "_" + uid2;
}
return uid2 + "_" + uid1;
}
Whenever I make a post document, I use uidsToQueryIdentifier() function as the value to the field queryIdentifier.
I am running this query on the client side with the following security rules and getting permission denied. The user object is authenticated and has a uid.
match /posts/{postId} {
allow read: if request.auth.uid == resource.data.to ||
request.auth.uid == resource.data.from;
allow write: if true;
}
const queryIdentifier = uidsToQueryIdentifier(user.uid, friend.uid);
let query = firestore().collection("posts")
.where("queryIdentifier", "==", queryIdentifier)
.orderBy("createdAt")