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

2 messages · Page 1 of 1 (latest)

pallid horizon
#

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
};`

feral steppeBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)