Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set cookies in nextjs

In my next.js project,I want to set cookies when user logs in. with document.cookies(something) it is setting cookies, but it is limiting to set only one cookie. If I give more than one cookie it is taking only the first element. In both cases I am not able to get cookie values in the pages.It is giving document is not defined error.I tried using

https://github.com/js-cookie/js-cookie,

with this I am able to set and get cookies,I am not able to secure my cookies. It will be great if you can solve this or suggest me some methods.

Thanks in advance.

like image 680
Logeswari Avatar asked Nov 27 '22 13:11

Logeswari


1 Answers

I'd suggest using https://www.npmjs.com/package/nookies as it's kinda tricky to do manually.

like image 165
pureth Avatar answered Nov 29 '22 03:11

pureth