CSR-759 Update how session ID cookies are saved and updated

This commit is contained in:
Katie 2022-08-17 09:25:51 -04:00
parent 402cdef7e7
commit b526fc059f
3 changed files with 44 additions and 8 deletions

View file

@ -10,7 +10,7 @@ export function updateOrCreateFunnelCookie() {
const shouldSuppressConceptFunnel = getFunnelCookie()?.SuppressConceptFunnel;
// Create the cookie
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()};`;
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()}`;
// Set up cookie with all the props.
setFunnelCookieProperties({
@ -106,10 +106,17 @@ export function getSessionIdValue(){
return '00000000-0000-0000-0000-000000000000';
}
export function setCookieProperties(properties) {
/*
Updates session ID cookie with new expiration date
*/
export function updateSessionIdCookie() {
createCookie(cookieNames.SESSION_ID, getSessionIdValue(), { maxAge: 60 * 30 });
}
export function setCookieProperties(properties, { useDefaultFunnelCookieAttributes = true, maxAge }) {
if (typeof properties == "object") {
Object.keys(properties).forEach(key => {
document.cookie = `${key}=${properties[key]}`;
createCookie(key, properties[key], { useDefaultFunnelCookieAttributes, maxAge });
});
}
}
@ -135,12 +142,34 @@ function setFunnelCookieProperties(properties) {
});
const cookieValueJson = JSON.stringify(cookie);
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()}`;
createCookie(cookieNames.FUNNEL_SESSION_INFO, cookieValueJson, {});
}
}
}
/*
Used to create a cookie.
`useDefaultFunnelCookieAttributes` will set the path and domain to our defaults
*/
function createCookie(key, value, { useDefaultFunnelCookieAttributes = true, maxAge, isSecure = true }) {
let cookieToAdd = `${key}=${value}; `;
console.log(isSecure)
console.log(useDefaultFunnelCookieAttributes)
if (useDefaultFunnelCookieAttributes) {
cookieToAdd += `path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()} `;
}
if (isSecure) {
cookieToAdd += `secure; `;
}
if (maxAge) {
cookieToAdd += `max-age=${maxAge};`;
}
document.cookie = cookieToAdd;
}
/*
Gets current domain without the subdomain for cookie.
*/

View file

@ -122,10 +122,14 @@ export default {
if (response.data) {
if (response.data.sessionKey && skey === 0) {
setCookieProperties({ [cookieNames.SESSION_KEY]: response.data.sessionKey});
setCookieProperties({ [cookieNames.SESSION_KEY]: response.data.sessionKey}, {
useDefaultFunnelCookieAttributes: false
});
}
if (response.data.sessionId && sid === '00000000-0000-0000-0000-000000000000') {
setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId});
setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId}, {
maxAge: 60 * 30 // 30 minutes
});
}
}
},

View file

@ -10,7 +10,7 @@ import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper";
// Heritage integration
import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper";
import { updateOrCreateFunnelCookie, getFunnelCookie } from "@/helpers/heritage-integration/cookie-helper";
import { updateOrCreateFunnelCookie, getFunnelCookie, updateSessionIdCookie } from "@/helpers/heritage-integration/cookie-helper";
import { loadOrderIfPresent, saveOrder } from "@/helpers/heritage-integration/order-helper";
import { getPageToRouteExistingOrderTo, navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper";
@ -31,6 +31,9 @@ const routes = [
if (analyticsMixin.methods.noSession()) {
await analyticsMixin.methods.initSession();
}
else {
updateSessionIdCookie();
}
if (getFunnelCookie()?.SuppressConceptFunnel) {
await navigateToHeritageFunnel(false);