I'm trying to secure my database and i want to secure the messages. My structure is messages/{chatid}/chat/messageArray (the chatid is like userid1-userid2). So i would like to check in security rules if chatid contain userid. I tried something it's working in simulator but i have a problem because in my code i query collection group and firestore deny acces. I make something like db.collection("messages").where("users", "array-contains", user.uid).onSnapshot..... If someone know how can i secure messages data i could be great.
match /messages/{chatId}/{document=**} {
allow read, write: if chatId.matches('.*'+request.auth.uid+'.*');
}