next js signed cookie
Unanswered
Saltwater Crocodile posted this in #help-forum
Saltwater CrocodileOP
How to use signed cookie in next.js
In express I can use cookie-parser package with
res.cookie("key",value,{signed:true})
In express I can use cookie-parser package with
res.cookie("key",value,{signed:true})
22 Replies
Are you trying to set a cookie and jwt sign it?
@Saltwater Crocodile
Saltwater CrocodileOP
No
Signed cookie means if I have the secret key that I can pass in the cookie parser function no one can't get the cookie without the secret key
In express we have two kind of cookie on is res.cookie and res.signedCookie
You can look into this
Yeah that's pretty much the same as JWT signing it
I'm pretty sure in Next there's no way to do that
Best bet is to look into JWT
It's the smae thing as what you described
as you can't get the cookie value unless you have the secret
I would use
jose or jsonwebtoken@Saltwater Crocodile
Saltwater CrocodileOP
@Jesse thank you for your valuable reply. yeah, it's a way to do that but a signed cookie was the best option.
If you really want to use cookie-parser you still can in Next, but you're going to have to manually sign each cookie instead of getting your server to do it for each one like you would in express
However things like res.signedCookies won't work
when you create a cookie you'll have to sign it
and when you read it in your server you'll have to decode it
@Saltwater Crocodile