How to redirect to specific path in Nextjs 14 app route after login?

Hi,

I’m using nextjs 14 with app route. I want to redirect the user to a specific path after login, such as /dashboard.
In the api route:
Firstly, I tried to add returnTo in handleLogin function, it doesn’t work.
Then, I also tried to add afterCallback function to redirect user to the path according to this document , it throw this error

Codes are below:

// app/api/auth/[auth0]/route.js
import { handleAuth, handleCallback, handleLogin } from "@auth0/nextjs-auth0";
import { redirect } from "next/navigation";

export const GET = handleAuth({
  //   login: handleLogin({
  //     returnTo: "/dashboard",
  //   }),
  callback: handleCallback({
    afterCallback: () => {
      redirect("/dashboard");
    },
  }),
})
1 Like

resolved by Unable to navigate on afterCallback · Issue #1600 · auth0/nextjs-auth0 · GitHub

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