nookies
nookies copied to clipboard
Cookies = {} server side
I'm setting a cookie server side. When I check the browser, the cookie is set properly. But when I set the cookie and immediately after that try to get it, it is undefined.
example code:
setCookie(isServer ? ctx : {}, 'testCookie', 'cookie value', {path: '/'});
const testCookie = parseCookies(isServer ? ctx : {}).testCookie;
console.log(testCookie);
The code above logs me undefined. This is happen in getInitialProps in next.js. When I try it client side (same code in ComponentDidMout), everything is working properly. Is nookies are async when are used server side? How to read the cookie, immediately after set it on server side?
you should probably provide path: '/' with the options when reading the cookie:
parseCookies(isServer ? ctx : {}, { path: '/' }).testCookie
you should probably provide path: '/' with the options when reading the cookie:
parseCookies(isServer ? ctx : {}, { path: '/' }).testCookie
It doesn't work