Reputation: 3560
I'm using Firebase & iOS and trying to validate when a user tries to submit a comment.
Here are my rules:
{
"rules": {
"comments": {
".read": true,
".write": "auth.uid != null",
"$comment_id": {
".validate": "newData.isString() && newData.val().length < 100"
}
}
}
}
Here is my database structure:
The comment that has been posted successfully was when I deleted the ".validate"
portion. I've also tried putting ".validate": "newData.isString() && newData.val().length < 100"
outside of the the $comment_id
block but this still resulted in failure.
Regardless, I get this error from the simulator when I try to add a comment:
Why isn't my ".validate"
working? What am I missing?
Upvotes: 1
Views: 394
Reputation: 598847
Your data path is /comments/$comment_id/comment
. Your validation rule doesn't cater for that last comment
in there.
{
"rules": {
"comments": {
".read": true,
".write": "auth.uid != null",
"$comment_id": {
"comment": {
".validate": "newData.isString() && newData.val().length < 100"
}
}
}
}
}
These rules will work. But I'd probably update the data structure to remove the comment
node, since it doesn't add any value.
Upvotes: 1