I have got the following:
match /direct/{postId} {
allow read, write: if postId.includes(request.auth.uid);
}
However, I would like to only allow read, write if the document ID (postId) contains the string. .includes is not working for me in security rules.
Edit: it should match a substring instead of the entire document id
Edit2

collection called direct where each document ID is a string which contains 2 uids in it’s name.
Any help would be appreciated. Thanks.
The document ID is a string, and as far as I can see the String class in security rules doesn't have an include method.
It does have a matches method though, so you can use that to test whether the document ID contains a substring with a regular expression.
Something like:
match /direct/{postId} {
allow read, write: if postId.matches(request.auth.uid);
}
A working read where the postId matches the UID of the user:

Trying to read another document:

Update: to test for a substring:
allow read: if postId.matches(".*"+request.auth.uid+".*");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With