diff --git a/src/App.js b/src/App.js index 3e8f0a45b..9f3044c17 100644 --- a/src/App.js +++ b/src/App.js @@ -32,7 +32,7 @@ export default class StripesCore extends Component { this.store = configureStore(initialState, this.logger, this.epics); this.actionNames = gatherActions(); - registerServiceWorker(okapiConfig.url, this.logger); + registerServiceWorker(okapiConfig, this.logger); } componentWillUnmount() { diff --git a/src/service-worker.js b/src/service-worker.js index 62df2c97e..21b51f25c 100644 --- a/src/service-worker.js +++ b/src/service-worker.js @@ -8,6 +8,8 @@ let tokenExpiration = null; /** string FQDN including protocol, e.g. https://some-okapi.somewhere.org */ let okapiUrl = null; +let okapiTenant = null; + /** categorical logger object */ let logger = null; @@ -109,6 +111,10 @@ const rtr = async (event) => { isRotating = true; return fetch(`${okapiUrl}/authn/refresh`, { + headers: { + 'content-type': 'application/json', + 'x-okapi-tenant': okapiTenant, + }, method: 'POST', credentials: 'include', mode: 'cors', @@ -332,14 +338,14 @@ self.addEventListener('activate', async (event) => { /** * eventListener: message - * listen for messages from clients and dispatch them accordingly. - * OKAPI_URL: store + * listen for messages from @folio/stripes-core clients and dispatch them accordingly. */ self.addEventListener('message', async (event) => { if (event.data.source === '@folio/stripes-core') { console.info('-- (rtr-sw) reading', event.data); - if (event.data.type === 'OKAPI_URL') { - okapiUrl = event.data.value; + if (event.data.type === 'OKAPI_CONFIG') { + okapiUrl = event.data.value.url; + okapiTenant = event.data.value.tenant; } if (event.data.type === 'LOGGER') { diff --git a/src/serviceWorkerRegistration.js b/src/serviceWorkerRegistration.js index 07085b9e3..b29e6e8af 100644 --- a/src/serviceWorkerRegistration.js +++ b/src/serviceWorkerRegistration.js @@ -10,11 +10,11 @@ * immediately claims control. Otherwise, no RTR would occur until after a * reload. * - * @param {string} okapiUrl + * @param {object} okapi config object * @param {function} callback function to call when receiving any message * @return void */ -export const registerServiceWorker = async (okapiUrl, logger) => { +export const registerServiceWorker = async (okapiConfig, logger) => { if ('serviceWorker' in navigator) { try { let sw = null; @@ -42,7 +42,7 @@ export const registerServiceWorker = async (okapiUrl, logger) => { // if (sw) { logger.log('rtr', '<= sending OKAPI_URL', sw); - sw.postMessage({ source: '@folio/stripes-core', type: 'OKAPI_URL', value: okapiUrl }); + sw.postMessage({ source: '@folio/stripes-core', type: 'OKAPI_CONFIG', value: okapiConfig }); logger.log('rtr', '<= sending LOGGER'); sw.postMessage({ source: '@folio/stripes-core', type: 'LOGGER', value: logger }); } else {