Created
November 30, 2018 16:13
-
-
Save jefBinomed/e8ea6bcc7207d473e3a8d8b5a5f599c3 to your computer and use it in GitHub Desktop.
2018-countdown-security-firestore
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
service cloud.firestore { | |
match /databases/{database}/documents { | |
// Generic method that checks if the email of the currently authenticated user is contained in the admin collection | |
function isAdmin() { | |
return request.auth != null | |
&& get(/databases/$(database)/documents/admins/adminList).data[request.auth.token.email] == true | |
&& request.auth.token.email_verified == true; | |
} | |
// The admin collection is in read only for the admins | |
match /admins/{document=**} { | |
allow read: if isAdmin(); | |
allow write, delete, update: if false; | |
} | |
// To update a planet, you have to be the user that create it or to be an admin. Everyone logged can read the data of a planet (because there is nothing critical in it) | |
match /planets/{planetId} { | |
allow update, delete: if request.auth.uid == planetId | |
|| isAdmin(); | |
allow read, create: if request.auth.uid != null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment