Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookies = {} server side #566

Open
denny7 opened this issue Nov 24, 2022 · 2 comments
Open

Cookies = {} server side #566

denny7 opened this issue Nov 24, 2022 · 2 comments

Comments

@denny7
Copy link

denny7 commented Nov 24, 2022

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?

@viniciusdacal
Copy link

you should probably provide path: '/' with the options when reading the cookie:

parseCookies(isServer ? ctx : {}, { path: '/' }).testCookie

@denny7
Copy link
Author

denny7 commented May 23, 2023

you should probably provide path: '/' with the options when reading the cookie:

parseCookies(isServer ? ctx : {}, { path: '/' }).testCookie

It doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants