Created
September 26, 2017 20:45
-
-
Save ThadeuLuz/367780442c6925e9d43c0114db781154 to your computer and use it in GitHub Desktop.
A better stack for your Firebase Rules - Bolt example
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
// Indicates if a user is logged in | |
imLoggedIn() { | |
auth != null | |
} | |
// Checks for the correc user id | |
myUidIs(uid) { | |
imLoggedIn() && auth.uid == uid | |
} | |
// Checks if user is the server | |
imServer() { | |
myUidIs('SERVER') | |
} | |
// User Profile type | |
type User { | |
displayName: String, | |
age: Number | |
} | |
// Adds server read access to all profiles at once (allows search) | |
path /users { read() { imServer() } } | |
// User rules for read and write | |
path /users/{userId} is User { | |
read() { myUidIs(userId) } | |
write() { myUidIs(userId) || imServer() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment