Hello,
This is how I used to get my cookies using pages/api:
// everything works here ✅
const { affiliate } = req.cookies;
However, I can't get any cookies using the new app directory api routes:
// affiliate is undefined ❌
import { NextResponse } from 'next/server';
import { cookies } from 'next/headers';
export async function POST(request: Request) {
const cookieStore = cookies();
const affiliate = cookieStore.get('affiliate');
return NextResponse.json({
affiliate,
});
}
Am I doing something wrong here?