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:

JavaScript 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.


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">