Last active
February 20, 2018 18:04
-
-
Save yonahforst/c29b80f7a2950a5ce85cfc88598a4213 to your computer and use it in GitHub Desktop.
database rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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