Ensure pre-user-registration hook fires after entering email with Identifier First

I have Identifier first set up for our app. It has been using Username-Password-Authentication so far. In addition to adding passwordless email logins, we wanted to redirect the user to an external site if their account hasn’t been migrated in our system yet.

This means that after they enter their email, we want to redirect them to a known external page.

I’ve tried using the pre-user-registration trigger, but that doesn’t seem to run on the login page. Only when I test the passwordless email login.

Hi @mwhite,

Welcome to the Auth0 Community!

You could use a Post-Login action script to redirect your users to an external page after they log in. Check out our Redirect with Actions documentation.

Let me know if you have any questions.

Thanks,
Rueben

This would need to be before they log in, as they would not yet have an account on auth0, and thus cannot provide a valid username/password combo to get to that trigger.

Hi @mwhite,

Thanks for the clarification.

The pre-user registration action only triggers during a signup event, not a login attempt. Therefore, when a user enters their email on the login page through Identifier First, the pre-user registration action script will not execute. Additionally, redirecting in Actions is only supported in post-login flows.

As a workaround, you could use a post-login action to check whether the user has migrated to your system and then perform a conditional redirect.

For example:

exports.onExecutePostLogin = async (event, api) => {
  if (event.user.app_metadata && !event.user.app_metadata.migrated) {
    api.redirect.sendUserTo("https://my-app.exampleco.com");
  }
};
exports.onContinuePostLogin = async (event, api) => {
  api.user.setAppMetadata("migrated",true)
}

Thanks,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.