getUser.
This script is required for automatic migration to Auth0, and conditionally required without migration enabled depending on the operations configured for the connection. Auth0 recommends you set permanent user_id on the returned user profile to avoid creating duplicate users.
When Import Users to Auth0 is enabled, the Get User script runs when a user attempts to sign up to check if the user already exists in the external user store.
The Get User script also runs when a user attempts to:
- Change their email address (Change Email script)
- Log in (Login script)
- Change their password (Change Password script)
- Sign up (Create script)
- Change their email address (Change Email script)
- Change or reset their password (Change Password script)
Get User function
ThegetUser function should:
- Send the user’s identifier to the external database’s API.
- Return the profile data of the user if the user was found.
- Return an error if there was an issue determining whether the user exists or not.
Definition
ThegetUser function accepts two parameters and returns a callback function:
This is a pseudo-JavaScript example of how you could implement the
getUser function:
Callback function
Thecallback function is used to pass user profile data or error data through the pipeline.
Definition
Thecallback function accepts up to two parameters and returns a function:
Return the user profile (user found)
If the user is found, pass anull value to the error parameter, and pass the user’s profile data to the profile parameter in normalized form:
user_metadata, app_metadata, and mfa_factors fields.
Return no user profile (user not found)
If the user is not found, pass anull value to the error parameter, and omit the profile parameter:
Return an error
If an error occurs, pass error data to theerror parameter with relevant information about what went wrong: