Storing and retrieving cookie

Anyone successfully stored cookie in one route handler and retrieving it in another route handler?
14 Replies
Revaycolizer
RevaycolizerOP16mo ago
I found a repo where someone set cookie and retrieve it in api route and consumed it successfully but when I implemented the same thing still couldn't achieve what he achieved I think the last version may have some bugs
Sturlen
Sturlen16mo ago
if you mean getting the cookies from an incoming request, then yes, you can do that in route handler https://nextjs.org/docs/app/building-your-application/routing/route-handlers#cookies if you want to store the contents on the server, then you'd need to store it yourself in a database or KV-store
Routing: Route Handlers
Create custom request handlers for a given route using the Web's Request and Response APIs.
Revaycolizer
RevaycolizerOP16mo ago
What is a KV-store?
Neto
Neto16mo ago
KV store is a kind of database with a key value pair like a map or a hash map
Revaycolizer
RevaycolizerOP16mo ago
I think I should use that instead of cookies could you provide a link please
Neto
Neto16mo ago
a cookie is in the browser kv store can be redis (like from upstash) or the vercel one (also upstash)
Revaycolizer
RevaycolizerOP16mo ago
Yap but tried retrieving it when consuming an endpoint but shows null value but when I hit localhost:3000/api/cookie I get the value it's driving me crazy Which one is the best?
Neto
Neto16mo ago
they are the same lmao
Revaycolizer
RevaycolizerOP16mo ago
Then would you please direct on how to set it up if there's no any docs available
Neto
Neto16mo ago
Upstash Documentation
Getting Started - Upstash Documentation
Create a Redis compatible database in seconds
Neto
Neto16mo ago
Upstash Documentation
Next.js with Redis - Upstash Documentation
This tutorial shows how to use Upstash inside your Next.js application.
Revaycolizer
RevaycolizerOP16mo ago
Thanks a lot let me give it a try because I'm tired of cookies been stack for 5 days Can I install the package without a fresh initialization of project
Neto
Neto16mo ago
yeah
Revaycolizer
RevaycolizerOP16mo ago
Thanks I will be back in case anything goes wrong Can I get more information on how to use redis as I only see one example Wow Redis works like a charm
Want results from more Discord servers?
Add your server