How can you use cookies with superagent?

Use superagent.agent() (instead of plain old superagent) to make requests have persistent cookies. See 'Preserving cookies' in the superagent docs, or the code examples: agency.js, controller.test.js.


Seems like following code works fine;

req.set('Cookie', "cookieName1=cookieValue1;cookieName2=cookieValue2");


Since you mentioned you need to both get and set the cookie:

Get:

const request = await Superagent.get('...')

const cookie = request.header['set-cookie']

Set:

Superagent.post('...').set('Cookie', 'cookie_info')

If the issue is in sending cookies for CORS requests use .withCredentials() method described here

request
  .get('http://localhost:4001/')
  .withCredentials()
  .end(function(err, res) { })