Next 13 Include request and response in Page context, or some way of getting request and response for page #43362
Replies: 6 comments 4 replies
-
You have access to the request cookies and headers. See:
These are currently read-only, but we are working on an RFC for writing as well. |
Beta Was this translation helpful? Give feedback.
-
I have looked around Next.js code base and it appears that the Request is not exposed in any shape or form to the Server Components (in the /app). Instead, a The simplest solution, which doesn't mean the best, would be to enrich the I could attempt to do it and provide a PR but again, this may be something authors want to explicitly avoid doing? |
Beta Was this translation helpful? Give feedback.
-
Thumbs up, I can't seem to find a way to handle a form POST in a server component (search params is not enough obviously). |
Beta Was this translation helpful? Give feedback.
-
I have the same problem , the old approach was way more easier |
Beta Was this translation helpful? Give feedback.
-
It is necessary to increase the priority of the problem. |
Beta Was this translation helpful? Give feedback.
-
Was about to post this exact question. In a previous project I used iron-session for authentication and storing a few user profile properties. I did authentication and re-routing in middleware, which translates fine to Next 13. The issue is getting the profile from the session and passing it to component props, which requires access to the Request and Response objects. I previously did this using getServerSideProps. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the feature you'd like to request
I'm currently using next-session to manage my sessions.
In order to get the session, the request and response objects for a request are needed. In Next 12, this was done by using
getServerSideProps
, which had request and response objects in its context parameter. There is, to my knowledge, no replacement for getting the request and response objects in the new app folder routing system.Describe the solution you'd like
Currently I'd like to be able to write a server component like the following on "/app/create/page.tsx":
How exactly I get the request and response object isn't particularly important. These parameters could be added to pages, maybe layouts and templates, and any other type of special file deemed appropriate.
Describe alternatives you've considered
Currently, according to the file conventions docs page, the only 2 props are params and searchParams.
I've searched around the Next 13 docs to see if I could find a way to do it, but nothing sticks out to me.
I've looked into using iron-session, but it's API didn't suit my needs and it also hasn't addressed the issue I'm presenting here.
Beta Was this translation helpful? Give feedback.
All reactions