Dynamic Redirection from Login success

I have implemented authO in my Next13 app project. My login returns to root location now i want it to dynamic after success redirection currently i have this code in my route.js

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

export const GET = handleAuth({
  login: handleLogin({
    authorizationParams: {
      prompt: "login",
    },
    returnTo: "/",
  }),
  signup: handleLogin({
    authorizationParams: {
      prompt: "login",
      screen_hint: "signup",
    },
    returnTo: "/", // This is the default behavior
  }),
  loginFromProduct: handleLogin({
    authorizationParams: {
      prompt: "login",
    },
    returnTo: "/product-detail-2?id=1b2fec2c-d5f0-4ae9-a48b-67479f9b6ebb",
  }),
});

loginFromProduct should redirect back to the same product page currently i hardcoded it how can i make it dynamic i have the ids of product from where login button is activating

Hi @TalhaRizwan093

Welcome to the Auth0 Community!

In order to handle dynamic redirection from Login success you can use the state parameter to encode an application state that will put the user where they were before the authentication process started.

Redirect users with state parameter

Thanks,
Dawid

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