简体   繁体   中英

Cookie parser's "res.cookie('cookieName', {cookieData}); doesn't set a cookie

I'm working on with nodeJs , and ExpressJs .

recently, I had this issue :

after res.cookie('cookieName', {cookieValue}); my req.cookies is still empty.

Here is my code [when I set the cookie]

res
      .cookie('vendor', vendor,
        {
          expires: moment().add(CONF.server.tokens.expiration.short, 'h').toDate(),
          httpOnly: false,
        });

And here is my code [when i want to get this cookie]

 await request({
    method: 'POST',
    baseUrl: process.env.SERVER,
    uri: '/users/shops/' + req.cookies.vendor.vendorId + '/credits',
    headers: {
      'Authorization': 'Bearer ' + req.cookies.access_token,
      'User-Agent': req.get('User-Agent'),
      'X-Forwarded-For': req.ip
    },
    json: true,
    body: {
      packs: req.body.packs,
      stripeToken: req.body.stripeToken
    }
  });

When I use Visual studio code's debugger, here is what i got, an empty object : debugger screenShot

Thanks a lot for your precious help, have a nice day/night.

我认为您应该更改“ httponly = true”并通过res.send()发送响应

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM