Last active
September 26, 2017 20:37
Revisions
-
ThadeuLuz revised this gist
Sep 26, 2017 . 2 changed files with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ #Simple Firebase Rules Stack -
ThadeuLuz created this gist
Sep 26, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ node_modules rules.json 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ { "name": "devfest-2017-presentation", "version": "1.0.0", "description": "", "scripts": { "build": "firebase-bolt rules.bolt --output rules.json", "bolt": "nodemon --watch rules.bolt --exec \"npm run build\"", "pretest": "npm run build", "test": "targaryen --verbose rules.json tests.json", "targaryen": "nodemon --watch tests.json --exec \"npm run test\"" }, "author": "", "license": "ISC", "dependencies": { "firebase-bolt": "^0.8.2", "nodemon": "^1.12.1", "targaryen": "^3.0.2" } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ imLoggedIn() { auth != null } myUidIs(uid) { imLoggedIn() && auth.uid == uid } imServer() { myUidIs('SERVER') } type User { displayName: String, age: Number } path /users { read() { imServer() } } path /users/{userId} is User { read() { myUidIs(userId) } write() { myUidIs(userId) || imServer() } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ { "rules": { "users": { ".read": "auth != null && auth.uid == 'SERVER'", "$userId": { ".validate": "newData.hasChildren(['displayName', 'age'])", "displayName": { ".validate": "newData.isString()" }, "age": { ".validate": "newData.isNumber()" }, "$other": { ".validate": "false" }, ".read": "auth != null && auth.uid == $userId", ".write": "auth != null && auth.uid == $userId || auth != null && auth.uid == 'SERVER'" } } } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ { "root": { "users": { "RICK": { "displayName": "Rick Sanchez", "age": 60 }, "MORTY": { "displayName": "Morty Smith", "age": 14 } } }, "users": { "Rick": { "uid": "RICK" }, "Morty": { "uid": "MORTY" }, "Server": { "uid": "SERVER" } }, "tests": { "users": { "canRead": ["Server"], "cannotRead": ["Rick", "Morty"] }, "users/MORTY": { "canRead": ["Server", "Morty"], "cannotRead": ["Rick"] }, "users/RICK/age": { "canWrite": [{ "auth": "Rick", "data": 59 }] }, "users/RICK/displayName": { "canWrite": [{ "auth": "Rick", "data": "Pickle Rick" }], "cannotWrite": [ { "auth": "Rick", "data": null }, { "auth": "Rick", "data": 123 }, { "auth": "Rick", "data": { "no": "object" } } ] } } }