Skip to content

Instantly share code, notes, and snippets.

@adrian-afergon
Last active May 7, 2021 19:15
Show Gist options
  • Save adrian-afergon/d658b44b2cc7c8481287a964c0535818 to your computer and use it in GitHub Desktop.
Save adrian-afergon/d658b44b2cc7c8481287a964c0535818 to your computer and use it in GitHub Desktop.
Firestore complex rules
service cloud.firestore {
match /databases/{database}/documents {
match /exercises {
function getRole(role) {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.roles[role]
}
allow read: if getRole('subscriber') == true;
allow update: if getRole('editor') == true;
allow create, delete: if getRole('admin') == true;
}
match /{document=**} {
allow read, write: if (request.auth.uid != null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment