Auth0 - Adding Twitter Screen Names to a User with Actions
Grrrr. Auth0 have a nifty service to let users log in to your site using a social network. Users don't need an account with you, they can sign in with Twitter, Facebook, GitHub, etc.
But there's a bug which is five years old. Auth0 doesn't show the screen name of Twitter users (e.g. @edent
).
There was a workaround using their "rules" product. But rules are being removed next month and we all need to transition to "Actions". Why? Because fuck you, that's why. Auth0 have decoded that fixing bugs is less important than updating their logo yet again despite having updated it a couple of years ago.
Anyway, here's the new action you need:
JavaScriptexports.onExecutePostLogin = async (event, api) => {
// Set the nickname to be the screen_name for Twitter connections
if (event.connection.name === 'twitter' && event.user.screen_name) {
api.idToken.setCustomClaim('nickname', event.user.screen_name);
}
};
Thanks to Gianfranco Parascandolo for helping me figure it out.