I have a Post
object that has a userID
and categoryID
. I'm trying limit a user to create one post in one category. My database:
posts: {
ID: {
body: "Post Body",
ownerID: "Mike",
categoryID: "books"
}
}
users: {
"Mike": {
completeName: "Mike Douglas"
}
}
I don't want to allow 'Mike' to create another Post using category 'books'.
My Firebase's rule:
{
"rules": {
"post": {
".read": true,
".write": "(data.child('ownerID').val() != auth.uid && data.child('categoryID').val() != newData.child('categoryID').val())",
".validate": "newData.hasChildren(['body', 'ownerID', 'categoryID'])",
"$other": { ".validate": false },
}
}
}
Do Firebase has an way to explain that I'm talking about the same data?