Skip to content

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

@HarwinderSingh15

Description

@HarwinderSingh15

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions