0

The question may seem weird, but let me show what I mean:

Here, you post your credentials as the body of a post request, and then the response will somehow set a cookie that you passed into the header. It uses curl that I don't have any experience with, and trying to earn the same with node. I was trying to set it as a variable, but it didn't work:

const fetch = require('node-fetch')

let cookie = ''

const auth = () => fetch(
  `${URL}/rest/authenticate`, {
    method: 'POST',
    body: JSON.stringify(credentials),
    headers: {
      cookie
    }
  }
);

I was searching for the same problem mentioned by someone else, but couldn't really find anything.

How can I set the cookies this way to a variable, or even a local file in node like in the example linked?

Gergő Horváth
  • 3,195
  • 4
  • 28
  • 64

1 Answers1

0

This might work:

const options = {
    method: 'POST',
    headers: {
        cookie: 'accessToken=1234abc; userId=1234'
    }
};
const result = await fetch(`${URL}/rest/authenticate`, options);

Also, check out this other post on SO.

Algo7
  • 2,122
  • 1
  • 8
  • 19