Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cookie node.js express

I am trying to use cookies with express but I can't find how does it works

app.get('/test', function(req, res){
    req.signedCookies.test = "aa";
    console.log(req.signedCookies.test)
    res.send(req.signedCookies.test);
})

I have aa

but if I try the /test2 url just after

app.get('/test', function(req, res){
    console.log(req.signedCookies.test)
    res.send("test");
})

I have undefined

I also have no test cookie in my browser

Thanks :)

like image 374
Ajouve Avatar asked Jun 24 '26 02:06

Ajouve


1 Answers

If you want to send cookies, you have to set them in the response (res). Changing the value in the request (req) does nothing.

res.cookie('test', 'aa', { signed: true });

See the res.cookie docs.

like image 113
josh3736 Avatar answered Jun 28 '26 11:06

josh3736



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!