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", }); }
4 Replies
Maj
Maj2y ago
Can you show me ur api endpoint code?.
jakeAnon
jakeAnonOP2y ago
importing {headers} from "next/headers"
const headersList = headers();
const secret = headersList.get("secret");
importing {headers} from "next/headers"
const headersList = headers();
const secret = headersList.get("secret");
This is what worked for me now, thank you
Maj
Maj2y ago
sweet.
Want results from more Discord servers?
Add your server