Custom Email Provider user_id Format: Database Connection Email Verification Behavior
When implementing custom email providers in Auth0, admins may notice that user_id in the event object differs from what is expected, particularly during the email verification phase of Database Connection sign-ups. This article explains why this occurs and how to handle it in the custom email provider actions.
- Actions
- Custom Email Provider
- User Management
Standard Auth0 user_id formats consist of the identity provider ID and a unique ID, separated by a pipe character (for example, {identity provider id}|{unique id in the provider}).
However, when a Database Connection requires email verification at signup, the user has not completed the signup process when the verification email is triggered. Because the signup is incomplete, the user has not yet been formally assigned to the database connection. Consequently, the auth0| prefix is omitted from the event.user.user_id property in the Custom Email Provider action trigger.
This behavior is expected. Because the user has not fully completed the sign-up process, the connection prefix is not yet appended to the user_id.
As a workaround, the event.connection.name property can be used to identify the connection the user will be assigned to after sign-up is completed. This allows developers to build connection-specific logic or manually construct the future user_id when required for external API calls or logging.
- Navigate to the Auth0 Dashboard and select Branding > Email Provider > Custom Email Provider.
- Edit the Action that is processing the verification email.
- Reference
event.connection.namewithin the Action code to verify the target database connection. - Implement custom logic to handle or format the
user_idbased on that connection name.
Below is an example of how to utilize event.connection.name as a workaround in the Action code:
exports.onExecuteCustomEmailProvider = async (event, api) => {
console.log("Target Connection: ", event.connection.name);
console.log("Raw user_id: ", event.user.user_id);
if (event.connection.name === "Username-Password-Authentication") {
const expectedFullUserId = `auth0|${event.user.user_id}`;
console.log("Constructed future user_id: ", expectedFullUserId);
}
};