Next.js Discord

Discord Forum

Issue with Cookies in Nextjs

Unanswered
Spruce Grouse posted this in #help-forum
Open in Discord
Spruce GrouseOP
Hi, i have a layout.tsx in my root application. That i use "use client" in it to use usePathName.
My issue is im trying to reach to cookies in client side. Any of the packages i try to get coookies with ("next-cookies", "cookies-next", "js-cookie"), im seeing an issue. The cookie value is returning both console (client) and server side. I tried it on any basic page, component, layout its the same result. im getting 2 values. So when i try to use the cookie, getting up some error because client and server results are different with it.
how can i solve this? is there any way?

11 Replies

you are getting 2 values ?
European sprat
Do not make your root layout a client component
If you need to usePathname you put it in a client component then import that client component into the layout
@Ejayz || PiggyDev you are getting 2 values ?
Spruce GrouseOP
yes in vscode console it says undefined, and client console gives value
@European sprat Do not make your root layout a client component
Spruce GrouseOP
my layout uses use effect too😦
European sprat
Well it's wrong
Start there
Spruce GrouseOP
but i need to init some js packages
in useeffect
@Spruce Grouse yes in vscode console it says undefined, and client console gives value
it should be auto set the cookies by api . and would auto send it back to server
"next-cookies", "cookies-next", "js-cookie" if you are using one of this to get cookies probly it is miss spelled or not existing . have you set your cookies after they login and added it to the response request ?