next 13: cookies in server and client side
Unanswered
Largehead hairtail posted this in #help-forum
Largehead hairtailOP
hello, does anyone know how to handle cookies on client and server side at the same time with next13
4 Replies
@Largehead hairtail hello, does anyone know how to handle cookies on client and server side at the same time with next13
where do you want to handle them?
@alfon where do you want to handle them?
Largehead hairtailOP
I need to access both server-side and client-side cookies, as I have API calls that require authentication using JWT tokens, which I store in cookies.
Asian black bear
Assuming you use the
/app dir based on the next13. In a server component you can use the cookie helper to get them from the request, although it will prevent ISR/SSG rendering and use dynamic instead. https://nextjs.org/docs/app/api-reference/functions/cookies#cookiesgetnameOn the client, I am pretty sure you have to use the normal browser APIs for them like
document.cookie and maybe a library like https://www.npmjs.com/package/js-cookie