How to redirect new users to an onboarding page?

When new users log in for the first time, they should be taken to an onboarding page at Returning users go to instead. Should this be done using Auth0 actions? Or should it be specified in the handleCallback?

I’m using Next.js with a route at /api/auth/[...auth0].js where handleCallback is defined.

Hi @jeff14,

Welcome to the Auth0 Community!

To redirect your users to your preferred page, you will need to make sure of the following:

  1. The URL is added to your application’s Allowed Callback URLs list.
  2. The URL is specified in your redirect_uri query parameter in your login request (/authorize)

Using the Next.js SDK, there are 2 places where you can set this value.

By default, you can set this in the returnTo property in your Login handler’s Login Options.

You could also set this in the redirectUri property in your Callback handler’s Callback Options. If you do choose this approach, note that it will override the value set in your returnTo property.

Please let us know if you have any additional questions!


Thank you! I was wondering if I could somehow access the context.stats object from the callback handler? I need a way to distinguish between new users and returning users.

Hi @jeff14,

Thanks for following up.

Unfortunately, the context.stats property cannot be called in the Next.js SDK. For clarity, the context.stats is an object only callable inside of an Auth0 Rule. See Context Object Properties in Rules for more information.

For this to work, I recommend calling the Management API’s Get a user endpoint and filtering for the user’s logins_count attribute.

Alternatively, you could append the user’s logins_count as a custom claim in the access token and proceed with your logic that way.

I hope this helps!


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