Pre User Registration Flow
The Pre User Registration Flow runs before a user is added to a Database or Passwordless Connection.
Actions in this flow are blocking (synchronous), which means they execute as part of a trigger's process and will prevent the rest of the Auth0 pipeline from running until the Action is complete.
Triggers
Pre User Registration
The pre-user-registration
triggers runs when a user attempts to register through a Database or Passwordless connection. This trigger can be used to add metadata to the user profile before it is created or to deny a registration with custom logic.
References
Event object: Provides contextual information about the request to register a new user.
API object: Provides methods for changing the behavior of the flow
Common use cases
Deny registration by location
A pre-user-registration Action can be used to prevent a user from signing up.
/**
* @param {Event} event - Details about registration event.
* @param {PreUserRegistrationAPI} api
*/
exports.onExecutePreUserRegistration = async (event, api) => {
if (event.request.geoip.continentCode === "NA") {
// localize the error message
const LOCALIZED_MESSAGES = {
en: 'You are not allowed to register.',
es: 'No tienes permitido registrarte.'
};
const userMessage = LOCALIZED_MESSAGES[event.request.language] || LOCALIZED_MESSAGES['en'];
api.access.deny('no_signups_from_north_america', userMessage);
}
};
Was this helpful?
Set metadata in the user profile
A pre-user-registration Action can be used to add metadata to the user profile before it is created. Currently, you cannot add metadata to Passwordless users with a pre-user-registration Action.
/**
* @param {Event} event - Details about registration event.
* @param {PreUserRegistrationAPI} api
*/
exports.onExecutePreUserRegistration = async (event, api) => {
api.user.setUserMetadata("favorite_color", "purple");
};
Was this helpful?
Store a user ID from another system in the user profile
A pre-user-registration Action can be used to store a user ID from another system in the user profile.
const axios = require("axios");
/**
* @param {Event} event - Details about registration event.
* @param {PreUserRegistrationAPI} api
*/
exports.onExecutePreUserRegistration = async (event, api) => {
const remoteUser = await axios.get("https://my-api.exampleco.com/users", { params: { email: event.user.email }});
if (remoteUser) {
api.user.setAppMetadata("my-api-user-id", remoteUser.id);
}
};
Was this helpful?