Skip to content

Instantly share code, notes, and snippets.

@yonahforst
Last active February 20, 2018 18:04
Show Gist options
  • Save yonahforst/c29b80f7a2950a5ce85cfc88598a4213 to your computer and use it in GitHub Desktop.
Save yonahforst/c29b80f7a2950a5ce85cfc88598a4213 to your computer and use it in GitHub Desktop.
database rules
{
"rules": {
"messages": {
"$roomId": {
// users can only chat in their own private room. admins can chat anywhere.
".read": "$roomId === auth.uid || auth.token.admin === true",
"$messageId": {
// can only write new data, not modify old
".write": "($roomId === auth.uid || auth.token.admin === true) && !data.exists() && newData.exists()",
// must contain only userId and body
".validate": "newData.hasChildren(['userId', 'body'])",
"userId": {
// you can only create messages as yourself
".validate": "newData.val() === auth.uid"
},
"body": {
// body must be a non-empty string
".validate": "newData.isString() && newData.val().length > 0"
},
"$other": {
// all other fields are rejected
".validate": false
}
},
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment