'NextJS: Set custom header during client side rendering
I am trying to set a session token header for every rendering request sent to the server by Next.JS. The closest thing I have found so far from the docs is this: https://nextjs.org/docs/api-reference/next.config.js/headers
However, the settings in the link above doesn't work for me because next.config.js is loaded on the server-side, but the session token can only be generated from the client-side.
So how can i set custom HTTP Headers for every render request from the client-side instead?
Solution 1:[1]
You can do it in your _app.tsx
App.getInitialProps = async ({ ctx }) => {
ctx.res.setHeader("header", "value");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | niksya |
