vercel / next-learn

Learn Next.js Starter Code
https://next-learn-dashboard.vercel.sh/
MIT License
3.44k stars 1.8k forks source link

Response.redirect navigating to the url but not updating it in the address bar #666

Open HarwinderSingh15 opened 2 months ago

HarwinderSingh15 commented 2 months ago

Im using nextAuth@beta version to implement authentication in my nextjs14 app.

When user got logged in it is routing to the portal screen which is fine but after routing its not changing url in the address bar which is quite a problematic for me. I have search a lot about it but got nothing

`export const authConfig: NextAuthConfig = { pages: { signIn: "/login", }, callbacks: { async jwt({ token, user }) { if (user && user?.accessToken) { token.accessToken = user.accessToken; } return token; }, async session({ session, user, token }) { session.user = { name: session?.user?.name, email: session?.user?.email, image: session?.user?.image, accessToken: token?.accessToken, }; return session; }, authorized({ auth, request: { nextUrl, url } }) { const isLoggedIn = !!auth?.user; const isRootOrDashboard = nextUrl.pathname === "/" || nextUrl.pathname.startsWith("/portal");

    if (isRootOrDashboard) {
      if (!isLoggedIn) {
        return false
      } else if (nextUrl.pathname === "/") {
        return Response.redirect(new URL("/portal", nextUrl));
      }
    } else if (isLoggedIn) {
      return Response.redirect(new URL("/portal", nextUrl));
    }

    return true;

},

}, providers: [] }; `

mfpuentear commented 2 months ago

Same here, this fails in 14.2 but works in 14.1

HarwinderSingh15 commented 2 months ago

Same here, this fails in 14.2 but works in 14.1

Thank you much. It worked

Misfit-Ha commented 1 month ago

changing the version didn't work for me I was able to fix it thanks to this post https://github.com/vercel/next.js/issues/65936#issuecomment-2121071370