This is the code in my _middleware file located in the pages folder it keeps giving me the URL malformed error anytime a request is sent:
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");
}
It will deprecate soon if you want to use the redirect method you can create an absolute URL by
const url = req.nextUrl.clone()
url.pathname = '/login'
return NextResponse.redirect(url)