Last active
July 23, 2018 12:57
-
-
Save deltaepsilon/689cbf5eb706c027df5ea02094e07b85 to your computer and use it in GitHub Desktop.
Cloud Function to manage Custom Claims
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
const BAD_KEYS_REGEXP = /[\.|\/|$|#|\[|\]]/g; | |
module.exports = ({ admin, environment }) => ({ email, claims }) => { | |
const emailSlug = email.replace(BAD_KEYS_REGEXP, '|'); | |
return admin | |
.database() | |
.ref(environment.schema.customClaims) | |
.child(emailSlug) | |
.set({ email, claims }); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment