Next.js Discord

Discord Forum

Response.redirect in the auth.config.ts file is not changing url in the browser's address bar

Unanswered
HarryCodes posted this in #help-forum
Open in Discord
Hi guys,

First time to discord and to this channel.

I have searched alot bout this issue but got nothing.

I have mentioned my code below.

Navigation is working fine but the url is not getting changed after login or logout

If I complete the login and go the portal page. It still shows login url in the addressbar

Please help

thanks


import { NextAuthConfig } from "next-auth"; import { NextResponse } from "next/server"; 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 NextResponse.rewrite(new URL("/portal", url)); } } else if (isLoggedIn) { return NextResponse.rewrite(new URL("/portal", url)); } return true; }, }, providers: [], // Add providers with an empty array for now };

1 Reply

Please help