Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HarwinderSingh15 opened this issue May 7, 2024 · 3 comments

Comments

@HarwinderSingh15
Copy link

HarwinderSingh15 commented May 7, 2024

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
Copy link

Same here, this fails in 14.2 but works in 14.1

@HarwinderSingh15
Copy link
Author

Same here, this fails in 14.2 but works in 14.1

Thank you much. It worked

@Misfit-Ha
Copy link

Misfit-Ha commented Jun 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants