Custom Headers Nextjs13
Hello,
What is the correct way to access this custom header in next13?
Accessing the request.headers.secret used to work this way prior to updating but it is now undefined. I can see the value when I log request.headers as well as when I log my API_ROUTE_SECRET
any tips would be greatly appreciated
console.log(request.headers); // exists in here
console.log(request.headers.secret); // undefined
if (request.headers.secret !== process.env.API_ROUTE_SECRET) { return NextResponse.json({ message: "You are not authorized to call this API", }); }
if (request.headers.secret !== process.env.API_ROUTE_SECRET) { return NextResponse.json({ message: "You are not authorized to call this API", }); }
4 Replies
Can you show me ur api endpoint code?.
next.config.js Options: headers
Add custom HTTP headers to your Next.js app.
This is what worked for me now, thank you
sweet.