Next.js Discord

Discord Forum

Problems with the NextAPIRequest

Answered
LeonTM posted this in #help-forum
Open in Discord
Hi, I am building an api route at the moment. For those I wrote a function which validates the Access, meaning it just checks for the authorization header to be the value I want. Lets say it is "hello". But even if I set the authorization header in postman or within the fetch method is always undefined even if it is defined as hello in the request.headers map. What am I doing wrong here?
Answered by gin
import { headers } from 'next/headers'
 const headersList = headers()
 const auth = headersList.get('authorization')
View full answer

8 Replies

The function
The headers map
The console log for the authorization header, sorry I isnt null, just undefined
@LeonTM The function
import { headers } from 'next/headers'
 const headersList = headers()
 const auth = headersList.get('authorization')
Answer
Thanks for the quick help. But why is it like this?
@LeonTM Thanks for the quick help. But why is it like this?
cause the headers object is raw and needs to be parsed