diff --git a/packages/core-app-api/src/apis/implementations/IdentityApi/startCookieAuthRefresh.test.ts b/packages/core-app-api/src/apis/implementations/IdentityApi/startCookieAuthRefresh.test.ts index e2751788db..4db068deb9 100644 --- a/packages/core-app-api/src/apis/implementations/IdentityApi/startCookieAuthRefresh.test.ts +++ b/packages/core-app-api/src/apis/implementations/IdentityApi/startCookieAuthRefresh.test.ts @@ -166,8 +166,6 @@ describe('startCookieAuthRefresh', () => { stop(); }); - expect(error).toEqual([ - 'Session cookie refresh failed: Failed to get cookie again', - ]); + expect(error).toEqual(['Session cookie refresh failed']); }); }); diff --git a/packages/core-app-api/src/apis/implementations/IdentityApi/startCookieAuthRefresh.ts b/packages/core-app-api/src/apis/implementations/IdentityApi/startCookieAuthRefresh.ts index ce639890c0..597e1b7cc6 100644 --- a/packages/core-app-api/src/apis/implementations/IdentityApi/startCookieAuthRefresh.ts +++ b/packages/core-app-api/src/apis/implementations/IdentityApi/startCookieAuthRefresh.ts @@ -55,7 +55,7 @@ export function startCookieAuthRefresh({ try { const baseUrl = await discoveryApi.getBaseUrl(PLUGIN_ID); const requestUrl = `${baseUrl}/.backstage/auth/v1/cookie`; - const res = await fetchApi.fetch(`${requestUrl}`, { + const res = await fetchApi.fetch(requestUrl, { credentials: 'include', }); @@ -65,8 +65,6 @@ export function startCookieAuthRefresh({ ); } - firstError = true; - const data = await res.json(); if (!data.expiresAt) { throw new Error('No expiration date in response'); @@ -77,6 +75,8 @@ export function startCookieAuthRefresh({ throw new Error('Invalid expiration date in response'); } + firstError = true; + channel?.postMessage({ action: 'COOKIE_REFRESH_SUCCESS', payload: { expiresAt: new Date(expiresAt).toISOString() }, @@ -94,7 +94,7 @@ export function startCookieAuthRefresh({ errorBackoff * ERROR_BACKOFF_FACTOR, ); // eslint-disable-next-line no-console - console.error(`Session cookie refresh failed: ${error.message}`); + console.error('Session cookie refresh failed', error); errorApi.post( new Error( `Session refresh failed, see developer console for details`,