Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing quote cart issue wit the token storage change - affected by ht… #1327

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scripts/commerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ export function getAuthorization() {
} else {
env = 'prod';
}
const tokenInStore = sessionStorage.getItem(`${siteID}_${env}_apiToken`);
const parsedToken = JSON.parse(tokenInStore);
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 (parsedToken && parsedToken?.expiry_time > (new Date().getTime() / 1000)) {
authHeader.append('authentication-token', parsedToken.token);
} else if (getCookie(`${siteID}_${env}_apiToken`)) {
const apiToken = getCookie(`${siteID}_${env}_apiToken`);
authHeader.append('authentication-token', apiToken);
Expand Down
9 changes: 4 additions & 5 deletions scripts/delayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,19 @@ function sendCoveoEventProduct() {
async function getAuthToken() {
if (!refresh) {
refresh = true;
const siteID = window.DanaherConfig?.siteID;
const formData = 'grant_type=anonymous&scope=openid+profile&client_id=';
const authRequest = await fetch(`${baseURL}/token`, {
const authRequest = await fetch(`/content/danaher/services/auth/token?id=${siteID}`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
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(`${siteID}_${env}_apiToken`, data.access_token, expiresIn, '/');
localStorage.setItem(`${siteID}_${env}_refresh-token`, data.refresh_token);
sessionStorage.setItem(`${siteID}_${env}_apiToken`, JSON.stringify(data));
sessionStorage.setItem(`${siteID}_${env}_refresh-token`, data.refresh_token);
}
}
}
Expand Down
Loading