Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
nextjs: server cookie not load in getInitialProps

I save the cookie with /api/login/

import { serialize } from "cookie"

export default (req: any, res: any) => {
    res.setHeader(
        'Set-Cookie',
        serialize("token", req.body.token, {
            maxAge: 30 * 24 * 60 * 60,
            path: "/"
        })
    )

    res.json({ success: true })
}

After reload the page, I want to get the cookie:

import type { AppProps } from 'next/app'
import cookie from "cookie"

function MyApp({ Component, pageProps }: AppProps) {
    return <Component {...pageProps} />
}

MyApp.getInitialProps = async ({ req }) => {
    const cookies = parseCookies(req)
    console.log(req.headers.cookie)
    return {
        pageProps:  { cookies: req.headers.cookie }
    };
};

export default MyApp

My token saved in storage, but not show to me

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!