Skip to content

Instantly share code, notes, and snippets.

@katowulf
Created May 18, 2020 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katowulf/36196c88e0d5593c2021d8b5950c73af to your computer and use it in GitHub Desktop.
Save katowulf/36196c88e0d5593c2021d8b5950c73af to your computer and use it in GitHub Desktop.
Simple RTDB validation example
{
"aListOfRecords": {
// when querying our list, must get less than 50 at a time and be authenticated
".read": "auth != null && (query.limitToFirst <= 50 || query.limitToLast <= 50)",
"$aRecordId": {
// When fetching a single record, I must be logged in
".read": "auth != null",
// When writing a record, I must be logged in
".write": "auth != null",
// Validate my schema
"aNumberField": { ".validate": "newData.isNumber() && newData.val() > -1 && newData.val() < 51" },
"aStringField": { ".validate": "newData.isString() && newData.val().length < 4" }
// Disallow any fields not in my schema
"$other": { ".validate": false }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment