Skip to content

Cookies = {} server side #566

@denny7

Description

@denny7

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions