Nextjs-auth0 how to do conditonal returnTo based on the user roles?

Please include the following information in your post:

  • Which SDK this is regarding: Nextjs-auth0
  • SDK Version: latest
  • Platform Version: where do I get this?
  • Code Snippets/Error Messages/Supporting Details/Screenshots:

So I’m aware of this: handlers/login | @auth0/nextjs-auth0

and I know I can return “returnTo” with some path value to have user redirected to some page. But how to do it conditonally? I cannot seem to figure out how to get the user profile there. Neither the req or loginOptions seem to contain anything useful either.

The flow I’m going after is this:

  1. User authenticates on auth0 view
  2. User is redirected to their specific dashboard after redirect, post authentication.

But it does not seem possible. since

  1. If I try to do it with nextjs redirects (next.config.js: Redirects | Next.js) then the information about the profile is not accessible there
  2. If I try to do it with this handleLogin - again information seems to not be available
  3. By creating a single landing view and then redirecting when the user roles are available, results in an empty view rendering until the role is available through useUser.

Any ideas on how to approach the issue are welcome.