Redirect User After Login with Auth0 Actions

InstructorWill Johnson

Share this video with your friends

Send Tweet

You can use the post-login Action to redirect users before an authentication transaction is complete. This lets you implement custom authentication flows that require additional user interaction beyond the standard login form.

Call api.redirect.sendUserTo() with the URL you want to redirect to as a string

After the redirect, in your app resume authentication by redirecting the user to the /continue endpoint and include the state parameter from the URL.

If you don't send the original state back to the /continue endpoint, Auth0 will lose the context of the login transaction and the user will not be able to log in.

In your application redirect to: https://{yourAuth0Domain}/continue?state=abc123

After the user has been redirected to the /continue endpoint, the Action will resume by calling the onContinuePostLogin function.

For redirects to work properly, you must have a uncomment the onContinuePostLogin function even if the function is empty.

Check if the user has seen the announcement

  if (!event.user.app_metadata[''announcement_seen'']) {
    api.redirect.sendUserTo("http:://localhost:3000/announcement");
  }
};

If the user hasn't seen the announcement set the app_metadata

exports.onContinuePostLogin = async (event, api) => {
  api.user.setAppMetadata('announcement_seen', true);
};