Ajouve
Ajouve

Reputation: 10089

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 :)

Upvotes: 2

Views: 7200

Answers (1)

josh3736
josh3736

Reputation: 144912

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.

Upvotes: 9

Related Questions