getServerSideProps not getting the updated cookie from the middleware
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 21.1.0 Binaries: Node: 14.17.1 npm: N/A Yarn: 1.22.17 pnpm: N/A Relevant packages: next: 12.1.5-canary.4 react: 17.0.2 react-dom: 17.0.2
What browser are you using? (if relevant)
Chrome Version 99.0.4844.84 (Official Build) (arm64)
How are you deploying your application? (if relevant)
next start
Describe the Bug
In the Middleware, when I set the cookie to some new value or a new cookie and I need to use it in the getServerSideProps, I cant able to get those cookies.
Expected Behavior
I can able to see the cookie in the browser, but the new/updated cookie should be present in getServerSideProps, aswell.
To Reproduce
In Middleware.ts
const pages = ['/home/']; async function middleware(request: NextRequest) { if (pages.includes(request.nextUrl.pathname)) { return nextResponse.cookie('newCookie','some value') } }
in [page.tsx]
export const getServerSideProps: GetServerSideProps = async (context) => { console.log(context?.req?.headers); return {props:{}} }
I cant able to see the newCookie in the [page.tsx] console statement.
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:5 (1 by maintainers)
Top GitHub Comments
https://github.com/vercel/next.js/discussions/38650#discussioncomment-3148772
@iljamulders galaxy brain 👏