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 strongly recommends that the user_id you return on the user profile be permanent and consistent: for a given user, the Get User script should return the same user_id on every execution. See Return a consistent user_id for details. 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 a consistent user_id

Auth0 uses the user_id returned by the Get User script to identify the user across your tenant. For a given user, this value should be consistent: the Get User script should return the same user_id every time it runs for that user. Derive the user_id from a stable, permanent property of your source record (such as the database primary key), not from a value that changes between executions.
Returning an inconsistent user_id can create duplicate or orphaned users, and can break flows that rely on the identifier remaining stable.
Derive the user_id from a stable property of the source record, so the same user always maps to the same value.
Don’t generate a new or random user_id on each call. For example, returning a freshly generated UUID. This produces a different identifier every time the script runs for the same user.

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: