I've encountered an issue with the code in my _middleware
file that is located within the pages
folder. Every time a request is made, it keeps throwing a URL malformed error. Here's the code snippet:
const token = await getToken({req, secret: process.env.JWT_SECRET});
const {pathname, origin} = req.nextUrl;
if(pathname?.includes('/api/auth') || token){
return NextResponse.next();
};
if (!token && pathname !== "/login") {
return NextResponse.redirect("/login");
}