How to set cookies in nextjs

Viewed 27687

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.

2 Answers

You can't use the secure flag when your app is running on localhost unless you are running the application on https. To test if the secure flag is working, deploy the application on production or testing environment.

Related