Storing and retrieving cookie

Anyone successfully stored cookie in one route handler and retrieving it in another route handler?
14 Replies
Revaycolizer
Revaycolizer15mo 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
Sturlen15mo 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
Revaycolizer15mo ago
What is a KV-store?
Neto
Neto15mo ago
KV store is a kind of database with a key value pair like a map or a hash map
Revaycolizer
Revaycolizer15mo ago
I think I should use that instead of cookies could you provide a link please
Neto
Neto15mo ago
a cookie is in the browser kv store can be redis (like from upstash) or the vercel one (also upstash)
Revaycolizer
Revaycolizer15mo 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
Neto15mo ago
they are the same lmao
Revaycolizer
Revaycolizer15mo ago
Then would you please direct on how to set it up if there's no any docs available
Neto
Neto15mo ago
Upstash Documentation
Getting Started - Upstash Documentation
Create a Redis compatible database in seconds
Neto
Neto15mo ago
Upstash Documentation
Next.js with Redis - Upstash Documentation
This tutorial shows how to use Upstash inside your Next.js application.
Revaycolizer
Revaycolizer15mo 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
Neto15mo ago
yeah
Revaycolizer
Revaycolizer15mo 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