diff --git a/blocks/product-children/product-children.js b/blocks/product-children/product-children.js index c96ef5d0..18728eb0 100644 --- a/blocks/product-children/product-children.js +++ b/blocks/product-children/product-children.js @@ -5,7 +5,7 @@ import { getCookie, isOTEnabled, } from '../../scripts/scripts.js'; import { - getProductResponse, getSKU, + getProductResponse, } from '../../scripts/commerce.js'; customElements.define('product-tile', ProductTile); diff --git a/blocks/product-resources/product-resources.js b/blocks/product-resources/product-resources.js index 449832b6..b65898c3 100644 --- a/blocks/product-resources/product-resources.js +++ b/blocks/product-resources/product-resources.js @@ -4,7 +4,7 @@ import { getCookie, isOTEnabled, } from '../../scripts/scripts.js'; import { - getProductResponse, getSKU, + getProductResponse, } from '../../scripts/commerce.js'; const productResources = ` diff --git a/scripts/commerce.js b/scripts/commerce.js index e32d4e91..b52f1a43 100644 --- a/scripts/commerce.js +++ b/scripts/commerce.js @@ -14,13 +14,25 @@ export function getCommerceBase() { */ export function getAuthorization() { const authHeader = new Headers(); + const siteID = window.DanaherConfig?.siteID; + const hostName = window.location.hostname; + let env; + if (hostName.includes('local')) { + env = 'local'; + } else if (hostName.includes('dev')) { + env = 'dev'; + } else if (hostName.includes('stage')) { + env = 'stage'; + } else { + env = 'prod'; + } if (localStorage.getItem('authToken')) { authHeader.append('Authorization', `Bearer ${localStorage.getItem('authToken')}`); } else if (getCookie('ProfileData')) { const { customer_token: apiToken } = getCookie('ProfileData'); authHeader.append('authentication-token', apiToken); - } else if (getCookie('apiToken')) { - const apiToken = getCookie('apiToken'); + } else if (getCookie(`${siteID}_${env}_apiToken`)) { + const apiToken = getCookie(`${siteID}_${env}_apiToken`); authHeader.append('authentication-token', apiToken); } return authHeader; diff --git a/scripts/delayed.js b/scripts/delayed.js index e5a901c3..79da900b 100644 --- a/scripts/delayed.js +++ b/scripts/delayed.js @@ -131,10 +131,13 @@ async function getAuthToken() { body: formData, }); if (authRequest.ok) { + const siteID = window.DanaherConfig?.siteID; + const hostName = window.location.hostname; + const env = hostName.includes('local') ? 'local' : hostName.includes('dev') ? 'dev' : hostName.includes('stage') ? 'stage' : 'prod'; const data = await authRequest.json(); const expiresIn = data.expires_in * 1000; - setCookie('apiToken', data.access_token, expiresIn, '/'); - localStorage.setItem('refreshToken', data.refresh_token); + setCookie(`${siteID}_${env}_apiToken`, data.access_token, expiresIn, '/'); + localStorage.setItem(`${siteID}_${env}_refresh-token`, data.refresh_token); } } }