Skip to content

Instantly share code, notes, and snippets.

@SevanBadal
Last active April 11, 2024 13:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SevanBadal/96af2bc5621bf556e59d06671e85442e to your computer and use it in GitHub Desktop.
Save SevanBadal/96af2bc5621bf556e59d06671e85442e to your computer and use it in GitHub Desktop.
username isn’t a standard OIDC claim. So the Auth0 Universal Form (w/username, email, and password fields) returns the local-part of the email as the nickname. This is inconvenient when the client is relying on username data after the form is submitted. One solution is to use a Pre User Registration Flow - setting nickname equal to username.
/**
* You can create PreUserRegistration flows in the Actions -> Flows menu in your Auth0 dashboard
*
* Handler that will be called during the execution of a PreUserRegistration flow.
*
* @param {Event} event - Details about the context and user that is attempting to register.
* @param {PreUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the signup.
*
*/
exports.onExecutePreUserRegistration = async (event, api) => {
api.user.setAppMetadata('nickname', event.user.username);
};
@JHWelch
Copy link

JHWelch commented Mar 22, 2022

Thank you! This is exactly what I needed. I am very confused why Auth0 seems to state that this shouldn't be needed, when it definitely is.

@SevanBadal
Copy link
Author

Thank you! This is exactly what I needed. I am very confused why Auth0 seems to state that this shouldn't be needed, when it definitely is.

No problem! The other alternative that I've seen implemented uses the Auth0 Management API in server-side code to fetch the username at the start of a user session.

@Sonny949
Copy link

Thank you so much! This should really be fixed in auth0. Drove me insane.

@escherlies
Copy link

nice! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment