My posts contain user id for example, a user with a userId: “abcd1234z” would have a post of name “abcd1234z-1”. I can’t get the write rule check if the post title ($child) contains the userId within the name. I tried .contains and .matches options but must not be formatting the regex correctly.
{
"rules": {
"cloud": {
"news": {
".read": "auth.uid != null",
".write": "auth.uid != null",
}
},
"forum": {
"posts": {
"$child": {
".read": "auth.uid != null",
".write": "auth.uid != null && $child.matches(/*+request.auth.uid/)"
"$uid": {
".write": "auth.uid != null && $uid === auth.uid",
}
}
}
}
}
}
I recently tested this with .contains
instead of matches and that worked, so have a look at this question and the screenshot in my comment. In your case it should be something like: $child.contains(auth.uid)
.
Update: my comments/screenshots from the (now deleted) question:
This seems to work for me:
Can you show what doesn't work about your case?