getUser
.
This script is required for automatic migration, and conditionally required for legacy authentication depending on the operations configured for the connection. To avoid creating duplicate users, set a consistent, unchanging user_id
on the returned user profile for the same user.
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
- Create user
- Change email
- Change password
- Password reset
Get User function
ThegetUser
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
ThegetUser
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 thegetUser
function. For language-specific examples, read Language-specific script examples.
Callback function
Thecallback
function is used to pass user profile data or error data through the pipeline.
Definition
Thecallback
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.
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 anull
value to the error
parameter, and omit the profile
parameter.
Example
Return an error
If an error occurs, pass error data to theerror
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