Skip to main content
The Create script implements the defined function when a user is created. We recommend naming this function create. This script is optional. If it’s enabled, when a user signs up through or is created through the or Auth0 , Auth0 will run the script to create a corresponding user record in the external database. When a user is created in Auth0, Auth0 calls a series of scripts:
  1. Get User: Verifies that the user does not already exist in Auth0 or the external database.
  2. Create: Creates the user in the external database.
  3. Login: Verifies that the user was created successfully.

Create function

The create function should:
  • Send the user’s profile data to the external database’s API.
  • Return an error if the user creation operation failed.

Definition

The create function accept two parameters and returns a callback function:
This is a pseudo-JavaScript example of how you could implement the create function:

Encryption

Encrypt the password value using a cryptographic hash encryption library such as bcrypt to prevent any potential data leak. Avoid logging, storing, or transporting the password credential anywhere in its unencrypted form. For example:

Callback function

The callback function accepts one parameter and returns a function.

Definition

ValidationError type object

The ValidationError custom error type object allows you to pass data that will be displayed in your Tenant Logs. The ValidationError constructor accepts up to two parameters:

Return a success

If the user creation operation succeeded, return the callback function, and pass a null value as the error parameter:

Return an error

If an error occurs, return the callback function, and pass relevant error information to the the error parameter. For example, you can return an error with the value of user_exists for the errorCode parameter:
If you do, Auth0 records an fs tenant log event.

User object parameter

The user object parameter contains a predefined set of properties sourced from the user creation process:

Username property

If your custom database connection has the Requires Username setting enabled, then the Login and Get User scripts must support the username property, so you should store it in your external database.

User and app metadata

The user_metadata and app_metadata properties do not need to be stored in your external database. Auth0 automatically stores these values as part of the user profile record created internally.

Custom sign up fields

If you create and use custom fields during the sign up process, they will be included in the user object. For example:

Language-specific script examples

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

Troubleshoot

If you are unable to create a user in either your external user store or Auth0:
  1. Check the console.log() statements with Actions Real-Time Logs.
  2. Find the user in your legacy database and delete accordingly. If the partial user state is in Auth0, use the Management API’s Delete a User endpoint or Delete a Connection User endpoint.
  3. Make sure Import Mode is disabled, then configure the create script.