Created
May 18, 2020 15:27
-
-
Save katowulf/36196c88e0d5593c2021d8b5950c73af to your computer and use it in GitHub Desktop.
Simple RTDB validation example
This file contains hidden or 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
{ | |
"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