I have a middleware sitting between the client and /api/Blog/[id]/route.js async function GET(){...}
import { NextRequest, NextResponse } from "next/server";
import authenticate from "./middlewares/authenticate";
import { verifyToken } from "./lib/token";
import { cookies } from "next/headers";
export async function middleware(req: NextRequest, res: NextResponse) {
const { method, nextUrl } = req;
//GET Blog api
if (nextUrl.pathname.match(/^\/api\/Blog\/.*/) && method === "GET") {
const cookie = await cookies();
console.log(cookie); //ResponseCookies {}
const cookie2 = req.cookies;
console.log(cookie2); //RequestCookies {}
}
return NextResponse.next();
}
export const config = {
matcher: ["/api/Blog/:path", "/Blog/:path"],
};
The cookies are empty when i try to access them in middleware, but they are fine when i access them from the server /api/Blog. Does this have to do with the edgetime runtime middleware runs in? But I have other middlewares that can access cookies just fine.