Created
May 2, 2019 17:39
-
-
Save cutiko/ca003e0ea134c749b6a9f4615f8c1e99 to your computer and use it in GitHub Desktop.
Functions custom claims example
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
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