Last active
August 29, 2019 11:57
-
-
Save Viveckh/4e0a5c29e5e8cd14022184f9028935a3 to your computer and use it in GitHub Desktop.
Dating App - Firebase Realtime Database Schema - Messages
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
Show hidden characters
"messages": { | |
"$chat_id": { | |
// Only users who are on this chat can read/write | |
".read": "root.child('chats/' + $chat_id + '/members/' + auth.uid).exists()", | |
".write": "root.child('chats/' + $chat_id + '/members/' + auth.uid).exists()", | |
"$message_id": { | |
// the object to write must have required nodes, and also an existing msg can't be rewritten | |
".validate": "!data.exists() && newData.hasChildren(['message', 'author', 'timestamp'])", | |
// the message must be longer than 0 chars and less than 50 | |
"message": { ".validate": "newData.isString() && newData.val().length > 0 && newData.val().length < 50" }, | |
"author": { ".validate": "newData.val() === auth.uid" }, | |
"timestamp": { ".validate": "newData.val() <= now" }, | |
// no other fields can be included in a message | |
"$other": { ".validate": false } | |
} | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment