The Pre-user Registration trigger runs before a user is added to a Database or 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.
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.
You cannot currently use pre-user-registration Actions to add metadata to passwordless users.
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.
Copy
Ask AI
const axios = require('axios');const REQUEST_TIMEOUT = 2000; // Example timeout/*** Handler that will be called during the execution of a PreUserRegistration flow.** @param {Event} event - Details about the context and user that is attempting to register.* @param {PreUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the signup.*/exports.onExecutePreUserRegistration = async (event, api) => { try { // Set a secret USER_SERVICE_URL = 'https://yourservice.com' const remoteUser = await axios.get(event.secrets.USER_SERVICE_URL, { timeout: REQUEST_TIMEOUT, params: { email: event.user.email } }); if (remoteUser) { api.user.setAppMetadata('my-api-user-id', remoteUser.id); } } catch (err) { api.validation.error('custom_error', 'Custom Error'); }};
To use an npm library like axios, you must add the library to the Action as a dependency. To learn more, read the “Add a dependency” section in Write Your First Action.