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:
ParameterDescription
userObject. Contains user profile data sourced from the user creation process.
callbackFunction. Used to pass error data through the pipeline.

Example

This is a pseudo-JavaScript example of how you could implement the create function. For language-specific examples, read Language-specific script examples.

Encryption

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

Example

Callback function

The callback function accepts one parameter and returns a function.

Definition

ParameterTypeRequiredDescription
errorObjectRequiredContains error data.

Return a success

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

Example

Return an error

If an error occurs, return the callback function, and pass relevant error information to the the error parameter.

ValidationError type object

The ValidationError custom error type object allows you to pass data that will be displayed in your Tenant Logs.
Constructor
The ValidationError constructor accepts up to two parameters:
ParameterDescription
errorCode(Required) String. Specifies the type of error.
message(Optional) String. Contains information about the error.

Return error that user already exists

If you return an error with the value of user_exists for the errorCode parameter, Auth0 will record an fs tenant log event.
Example
Tenant Log Event FieldValue
Codefs
EventFailed Signup
DescriptionMy custom error message.

User object parameter

The user object parameter contains a predefined set of properties sourced from the user creation process:
PropertyDescription
client_idThe Auth0 application’s client ID if the user signed up through Universal Login, or the API key if the user was created through the Auth0 Dashboard or Management API.
tenantThe Auth0 tenant name.
emailThe user’s email address.
passwordThe user’s password in plain text.
usernameThe user’s username. Required only if the custom database connection has the Requires Username setting enabled.
connectionThe Auth0 connection name.
user_metadataContains the properties of the user_metadata object on the user’s Auth0 profile, if the object exists.
app_metadataContains the properties of the app_metadata object on the user’s Auth0 profile, if the object exists.

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.

Example

Language-specific script examples

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

JavaScript

ASP.NET Membership Provider (MVC3 - Universal Providers)

ASP.NET Membership Provider (MVC4 - Simple Membership)

MongoDB

MySQL

PostgreSQL

SQL Server

Windows Azure SQL Database

Request with Basic Auth

Troubleshoot

If you are unable to create a user in either your legacy database 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.

Learn more