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