Okay so I was working with NextJs implementing NextAuth for a page that's supposed to be accessed by admin only. Then, I was introduced to the new concept of the "middleware.ts" file, which apparently should execute a function for every determined route. But it is not working for me for some reason, check this out, I removed everything, and only kept a small console log just to know if the file is running, but it doesn't seem to log anything to the browser inspect or the terminal.
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
console.log("MIDDLEWARE EXECUTED FROM: ", request.url);
return NextResponse.next();
}
export const config = {
matcher: "/((?!api|_next/static|_next/image|favicon.ico).*)",
};
And yes, the file name is middleware.ts, located in the root directory.
please help if you can I've been trying to figure this out for 3 days.
Never mind, my problem was that I had to take the middleware file to "/src" not the root directory. thanks everyone <3