Skip to main content
The Get User script implements the function executed to determine the current state of existence of a user. We recommend naming this function 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: When Import Users to Auth0 is disabled, the Get User script runs when a user attempts to sign up to check if the user already exists in the external user store. If a user already exists in the external user store, it does not execute the Create script. The Get User script also runs when a user attempts to:

Get User function

The getUser 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

The getUser 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

The callback function is used to pass user profile data or error data through the pipeline.

Definition

The callback function accepts up to two parameters and returns a function:

Return the user profile (user found)

The profile data returned by the Get User script for a user must be consistent with the profile data returned by the Login script.
If the user is found, pass a null value to the error parameter, and pass the user’s profile data to the profile parameter in normalized form:
In addition to the standard fields, you can include the user_metadata, app_metadata, and mfa_factors fields.

Return no user profile (user not found)

If the user is not found, pass a null value to the error parameter, and omit the profile parameter:

Return an error

If an error occurs, pass error data to the error parameter with relevant information about what went wrong:
For more information, read Troubleshoot Custom Databases.

Language-specific script examples

Auth0 provides sample scripts for use with the following languages/technologies: