Redirecting to another page other than "/" using nextjs-auth0

I would like to achieve the same as the answer using nextjs-auth0 SDK. After successfully completing the login process, I would like to redirect the user to another URL i.ie. “/dashboard” not to “/”.

Code in my api/auth/[…auth0].js page

import { handleAuth, handleCallback } from "@auth0/nextjs-auth0";

export default handleAuth();

Configuration:

#AUTH0 CONFIGURATION 

AUTH0_SECRET=*****************************************
AUTH0_BASE_URL=http://localhost:3000
AUTH0_ISSUER_BASE_URL=https://****.us.auth0.com
AUTH0_CLIENT_ID=*****************************************
AUTH0_CLIENT_SECRET=*****************************************
AUTH0_AUDIENCE=*****************************************

Other information:
SDK: nextjs-auth0
version: ^1.5.0
next-js: 11.0.1

How can I achieve it? Please let me know if the question is not clear.

Bumping!!!

I will highly appreciate your help/hints.

If you’re looking to send all signed in users to the same path, here’s the code I am using

import { handleAuth, handleLogin } from "@auth0/nextjs-auth0";

export default handleAuth({
  async login(req, res) {
    await handleLogin(req, res, {
      returnTo: "/##DESIREDPATH##",
    });
  },
});

I do know you can use some neat stuff with the returnTo configurations, I’d check out the SDK directly for more specific exmaples
https://github.com/auth0/nextjs-auth0

5 Likes

Thanks for sharing it with the rest of community!

1 Like

Thank you so much. I will check the SDK return to configuration.

No worries! Let us know if you have any other questions down the road!

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