3

I'm using Superagent's agent() method to enable cookies when making HTTP requests. This is my code:

const agent = request.agent();
const login = await agent
    .post("http://localhost:3000/login")
    .field("email", "john@doe.com")
    .field("password", "test");

console.log("result is: ", login);

All is well, I can see in the dump that the Cookie is present, but I have no idea how to extract its value from the response object returned by Superagent. I checked the docs but this information is missing.

How do I extract my cookie from this reponse? I can access the string value with login.req._header but it contains all the headers and I don't think this is the official way of getting a cookie (with parsing a string value by hand).

Adam Arold
  • 29,285
  • 22
  • 112
  • 207

1 Answers1

0

All your cookies are stored here

login.header['set-cookie']

It's a string you can split

MathKimRobin
  • 1,268
  • 3
  • 21
  • 52