Skip to content

Instantly share code, notes, and snippets.

@cutiko
Created May 2, 2019 17:39
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 cutiko/ca003e0ea134c749b6a9f4615f8c1e99 to your computer and use it in GitHub Desktop.
Save cutiko/ca003e0ea134c749b6a9f4615f8c1e99 to your computer and use it in GitHub Desktop.
Functions custom claims example
exports.userCreationListener = functions.auth.user().onCreate(user => {
const admins = {
"first@admin.com": true
};
const email = user.email;
if (!admins[email]) {
return false;
}
const uid = user.uid;
return admin.auth().setCustomUserClaims(uid, {superAdmin: true}).then(
()=>admin.database().ref(`users/${uid}`).set(true)).catch(error=>{
console.log("SUPER_ADMIN_UPDATE_ERROR", error);
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment