Created
June 17, 2021 06:54
-
-
Save pfiadDi/22e3e39b305e42b79e75493ec7abe85c to your computer and use it in GitHub Desktop.
Firestore restrict to certain users
This file contains hidden or 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
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