Skip to content

Instantly share code, notes, and snippets.

@pfiadDi
Created June 17, 2021 06:54
Show Gist options
  • Save pfiadDi/22e3e39b305e42b79e75493ec7abe85c to your computer and use it in GitHub Desktop.
Save pfiadDi/22e3e39b305e42b79e75493ec7abe85c to your computer and use it in GitHub Desktop.
Firestore restrict to certain users
function getAllowedUser() {
return get(/databases/$(database)/documents/settings/allowedUsers)
}
function validUser() {
let allowedUsers = getAllowedUser();
return request.auth.token.email in allowedUsers.data.emails
||
request.auth.token.email.split("@")[1] in allowedUsers.data.domains
}
match /{document=**} {
allow read, write: if request.auth != null && validUser() && request.auth.token.email_verified
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment