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, and conditionally required for legacy authentication 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.
If automatic migration is configured for the connection and the user profile has not yet been created, the script is executed whenever the following operations occur:
- Change email
- Sign up
- Password reset
If legacy authentication is configured for the connection, the script is executed whenever the following operations occur:
- Create user
- Change email
- Change password
- Password reset
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:
| Parameter | Type | Description |
|---|
email | String | The user’s email address. |
callback | Function | Used to pass error or profile data through the pipeline |
Example
This is a pseudo-Javascript example of how you could implement the getUser function. For language-specific examples, read Language-specific script examples.
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:
| Parameter | Type | Required | Description |
|---|
error | Object | Required | Contains error data. |
profile | Object | Optional | Contains the user’s profile data. |
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.
Example
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.
Example
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.
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
Axios
Stormpath
Learn more