Next.js Discord

Discord Forum

NextJS middleware not working on deployment

Unanswered
Alligator mississippiensis posted this in #help-forum
Open in Discord
Alligator mississippiensisOP
Hello, I have middleware working for my profile page, where only authenticated users can access. It works fine on localhost, but the moment i deploy it to vercel, it always redirect from profile page to the login page, even if im authenticated:

const { data: session, status } = useSession();
 const username = session?.user.username;


return (
    <>
      {session && (
        <>
          <div className="flex flex-row justify-center my-5">
            <Image
              src={placeholder}
              width={100}
              height={100}
              alt="No icon found"
              priority
            ></Image>
          </div>


Could anyone help? Can't post more because of char limit

2 Replies

Alligator mississippiensisOP
Forgot to show my middleware.ts:

export { default } from "next-auth/middleware";

export const config = { matcher: "/profile" };
Leafcutting bee
where is you middleware.ts file located?