next-learn icon indicating copy to clipboard operation
next-learn copied to clipboard

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

Open HarwinderSingh15 opened this issue 1 year ago • 5 comments

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: [] }; `

HarwinderSingh15 avatar May 07 '24 09:05 HarwinderSingh15

Same here, this fails in 14.2 but works in 14.1

mfpuentear avatar May 07 '24 11:05 mfpuentear

Same here, this fails in 14.2 but works in 14.1

Thank you much. It worked

HarwinderSingh15 avatar May 07 '24 12:05 HarwinderSingh15

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

Misfit-Ha avatar Jun 07 '24 17:06 Misfit-Ha

~changing the version didn't work for me~ I was able to fix it thanks to this post vercel/next.js#65936 (comment)

was it just a version change that fixed for you are is there something else you have to change? Im running into something similar with have a next redirect inside of auth middleware right now

jtyler-dev avatar Aug 24 '24 01:08 jtyler-dev

was it just a version change that fixed for you are is there something else you have to change? Im running into something similar with have a next redirect inside of auth middleware right now

If I remember correctly changing the version did not fix it for me, but following the comment I linked did

Misfit-Ha avatar Aug 25 '24 23:08 Misfit-Ha

changing the version didn't work for me but eventually I was able to fix it thanks to this comment vercel/next.js#65936 (comment)

It worked for me thank you so much

xRiku avatar Jan 14 '25 12:01 xRiku

Fixed here https://github.com/vercel/next-learn/pull/983

leerob avatar Jan 19 '25 15:01 leerob

changing the version didn't work for me but eventually I was able to fix it thanks to this comment vercel/next.js#65936 (comment)

It worked for me thank you so much

can you tell me please, which specific comment you follow ?

Bivishan1 avatar Mar 19 '25 01:03 Bivishan1

changing the version didn't work for me but eventually I was able to fix it thanks to this comment vercel/next.js#65936 (comment)

It worked for me thank you so much

can you tell me please, which specific comment you follow ?

Sorry, I can't really remember right now since a lot of time has passed, but it was probably adding the "redirectTo" in the signIn param object

xRiku avatar Mar 19 '25 01:03 xRiku

changing the version didn't work for me but eventually I was able to fix it thanks to this comment vercel/next.js#65936 (comment)

It worked for me thank you so much

can you tell me please, which specific comment you follow ?

Sorry, I can't really remember right now since a lot of time has passed, but it was probably adding the "redirectTo" in the signIn param object

can we connect in discord ?

Bivishan1 avatar Mar 19 '25 03:03 Bivishan1