In an iOS messaging app I am creating, an outline of the structure for the messages node is as follows
"messages": {
"$uid":{
".read": "auth.uid == $uid",
"$messageId":{
// insert .write rule here
"toUid":{
// if its a group message then there would be multiple "$toUid" children
"$toUid":{
},
},
"fromUid":{
"$fromUid":{
}
},
"timeStamp":{
},
"group":{
"isGroupMessage":{
},
"groupId":{
}
}
}
}
},
I would like to add a write rule after $messageId to ensure that the "$toUid" or "$fromUid" is equal to the $uid .
any ideas how I can do this?
Is the following the best way to do it:
".write": "newData.child('toUid').hasChild($uid) || newData.child('fromUid').hasChild($uid)",
** I have gone with the solution below - changes structure but is the quickest / safest security rules for us to use for now.
The MVP is initially not going to have group messages (may be irrelevant but the logic could be different) - so alternatively I could add a wildCard child variable "$friendUid" and then have the following rule below that.
"$messageId":{
"$friendUid":{
".write": "$uid == auth.uid || $friendUid == auth.uid",