NextSJ getServerSideProps Authorization header missing in axios call without setting in explizitly
Unanswered
American black bear posted this in #help-forum
American black bearOP
We get our Authorization header from i3access/ingress so the client calls the nextjs app already with an Authorization header fully set.
If we log it the middle where, it is logged correctly.
However, if we make an API call via axios within getServerSideProps, the header is not present and the request fails.
We need to explizitly set it like this:
This works, but needs to be implemented reusable and called within each serverSideProps. The idea was to get the headers in the middleware so all requests have the header without manually adding them for each server side request.
After some testing the headers are present within the middleware but are not added to the getServerSideProps function outbound requests.
If we log it the middle where, it is logged correctly.
However, if we make an API call via axios within getServerSideProps, the header is not present and the request fails.
We need to explizitly set it like this:
`getsServersideProps(ctx) .... { ...
const authHeader = ctx.headers['authorization']
axios.get(..., {headers:authHeader})
}This works, but needs to be implemented reusable and called within each serverSideProps. The idea was to get the headers in the middleware so all requests have the header without manually adding them for each server side request.
After some testing the headers are present within the middleware but are not added to the getServerSideProps function outbound requests.