plugin-api: How to access Cookies on incoming requests?

Hi, I can't quite figure out how to access cookies on incoming requests. Thanks for your help :D
11 Replies
Favna
Favna14mo ago
https://stackoverflow.com/a/3409200 Though if you’re talking about the authentication cookie specifically then it’s request.auth that you probably want.
Stack Overflow
Get and Set a Single Cookie with Node.js HTTP Server
I want to be able to set a single cookie, and read that single cookie with each request made to the nodejs server instance. Can it be done in a few lines of code, without the need to pull in a third
josh
joshOP14mo ago
Thanks! Is it also okay to do it via response.cookies.get('...')? It turns out that the thing I messed up was the setting of the cookie, I thought that (on another route), calling response.cookies.set('...', '...') would be the way to do it, but it seems as though I have to set it as a header? cuz now it works - first route response.setHeader, second route response.cookies.get
Favna
Favna14mo ago
you were first talking about incoming requests and now you're talking about outgoing responses so which is it
josh
joshOP14mo ago
sorry if it was unclear, the first route sets the cookie, which the second route should then read. I did not find an attribute such as response.cookies, on the request object, so I didn't know how to get the cookies. As it turns out the problem was with the first route already tho, because it did not set the cookie correctly. I fixed that by using setHeader instead of cookies.set. And now it is also possible to get the cookies in the second route, via response.cookies.get().
Favna
Favna14mo ago
so problem solved?
josh
joshOP14mo ago
yes, thanks for your help :)
Favna
Favna14mo ago
alright vanitas is great btw 😉
josh
joshOP14mo ago
haha thanks, however i gotta disappoint you, since the backstory for the name is quite different pepeFeelsBadMan
Favna
Favna14mo ago
As in not kingdom hearts vanitas?
josh
joshOP14mo ago
nope :/ some years ago when I was in school we were supposed to paint vanitas motives (https://en.wikipedia.org/wiki/Vanitas) and since it is all about the 'certainty of death' and I was really bad at video games, I chose it as my gamer tag
Favna
Favna14mo ago
guess you get that question more often
Want results from more Discord servers?
Add your server