Skip to content

Instantly share code, notes, and snippets.

@hscheuerle
Created May 24, 2021 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hscheuerle/fb58ce4728113139eb2540fd6430b5cf to your computer and use it in GitHub Desktop.
Save hscheuerle/fb58ce4728113139eb2540fd6430b5cf to your computer and use it in GitHub Desktop.
DocumentReference serialization is type path in Firestore rules, forward slash paths are type path in "raw" form. Here's a utility for checking ownership
function sentInvitation(invitationId) {
return exists(/databases/$(database)/documents/accounts/$(request.auth.uid))
&& get(/databases/$(database)/documents/invitations/$(invitationId)).data.invitedBy == /databases/$(database)/documents/accounts/$(request.auth.uid)
}
// In production, wrapping exists and get in small utilities is worth tradeoff in code readability
// chaining this with utility that null-checks auth and auth.uid helps read rule errors in unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment