Reputation: 47861
My required field validation rule seems to work in the dashboard rules simulator but I get permission denied when I try it out for real. Did I set it up correctly? (.msg is the message text)
{
"rules": {
"messages":{
".read": "auth.uid !== null",
".write": "auth.uid !== null",
".validate": "newData.child('msg').exists()",
"uid": {
".validate": "auth.uid === newData.val()"
}
}
}
}
I've also alternatively tried this syntax in the .validate
".validate": "newData.hasChildren(['msg','uid','uname'])"
And this also throws a permission denied error for me.
Here's the ios code
func sendMessage(text: String!) {
// *** STEP 3: ADD A MESSAGE TO FIREBASE
messagesRef.childByAutoId().setValue([
"msg":text,
"uname":self.senderDisplayName,
"uid":self.senderId
])
}
Upvotes: 2
Views: 1435
Reputation: 47861
I just needed to add the dynamic message id into the json
{
"rules": {
"messages":{
".read": "auth.uid !== null",
".write": "auth.uid !== null",
"$message_id":{
".validate": "newData.child('msg').exists()",
"uid": {
".validate": "auth.uid === newData.val()"
}
}
}
}
}
Upvotes: 7