Cannot access 'set-cookie' header from response

I am unable to access the ‘set-cookie’ headers from the response object of calling fetch. Here is a sample code that demonstrates this issue

import fetch from 'node-fetch';
const response = await fetch(`${BASE_URL}/loginWithEmail`, {
  method: 'POST',
  body: JSON.stringify(payload),
  headers: {
    'Content-Type': 'application/json',
  },
});

const rawCookies = response.headers.raw()['set-cookie']; // undefined

I’ve tested the code locally using node-fetch package and it works perfectly fine over there. Is it due to the environment forge is running on or am I missing something here?

The issue occurred due to using node-fetch package rather than @forge/api. After switching everything works as it should. Here is the modified version of the code.

import {fetch} from '@forge/api';
const response = await fetch(`${BASE_URL}/loginWithEmail`, {
  method: 'POST',
  body: JSON.stringify(payload),
  headers: {
    'Content-Type': 'application/json',
  },
});

const rawCookies = response.headers.raw()['set-cookie'][0]; 
1 Like