G
G
gbymp2021-12-30 13:54:11
React
gbymp, 2021-12-30 13:54:11

Why cookie is undefined?

I need to get the cookies via getInitialProps in the main component _app.ts, but for some reason the cookies are undefined, the code is:

function MyApp({ Component, pageProps }: AppProps) {
  return <Component {...pageProps} />
  )
}
MyApp.getInitialProps = async ({req}: NextPageContext) => {
            console.log(req.headers.cookie) //undefined
}

what to do? PS I use nextjs

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question