diff --git a/src/router/methods/before-each.js b/src/router/methods/before-each.js index ba6c41940..923059b34 100644 --- a/src/router/methods/before-each.js +++ b/src/router/methods/before-each.js @@ -1,20 +1,18 @@ -import { queryStrings } from "@/constants/query-strings"; import { sessionStorageKeyConstants } from "@/constants/session-storage"; import { getFunnelCookie, updateOrCreateFunnelCookie, } from "@/helpers/heritage-integration/cookie-helper"; -import { loadSessionIfPresent } from "@/helpers/heritage-integration/order-helper"; import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper"; import analyticsMixin from "@/mixins/analytics-mixin"; import { routeData, FUNNEL_START_PAGE } from "@/router/constants/routes"; -import { consumeQueryFromStash } from "@/router/methods/helpers/querystring-stash"; import { runExperiments } from "@/router/methods/helpers/run-experiments"; import { bailout } from "@/router/methods/error"; import { checkPagePrerequisites } from "@/router/methods/page-prerequisites"; import { checkLogParam } from "@/helpers/debug-log-helper"; import { debugLog } from "@/helpers/debug-log-helper"; +import { handleHeritageReturn } from "@/router/methods/helpers/handle-heritage-return"; export async function beforeEach(to, from) { try { @@ -52,11 +50,8 @@ export async function beforeEach(to, from) { } } - // If sent from heritage, need to load session. - const fromHeritageFlag = consumeQueryFromStash(queryStrings.FROM_HERITAGE); - if (fromHeritageFlag) { - await loadSessionIfPresent(true, routeData.SERVICE_LOCATION.name); - } + // Special logic when returning from insurance flow. + await handleHeritageReturn(to, from); // prettier-ignore { diff --git a/src/router/methods/helpers/handle-heritage-return.js b/src/router/methods/helpers/handle-heritage-return.js new file mode 100644 index 000000000..7914c8e0e --- /dev/null +++ b/src/router/methods/helpers/handle-heritage-return.js @@ -0,0 +1,16 @@ +import { queryStrings } from "@/constants/query-strings"; +import { consumeReferralQuerystrings } from "@/router/methods/helpers/consume-referral-info"; +import { loadSessionIfPresent } from "@/helpers/heritage-integration/order-helper"; +import { routeData } from "@/router/constants/routes"; + +export async function handleHeritageReturn(to, from) { + const fromHeritageFlag = to.query[queryStrings.FROM_HERITAGE]; + + if (fromHeritageFlag) { + // Get new referral info from querystring in case passed there. + await consumeReferralQuerystrings(); + + // load session with new cookie + await loadSessionIfPresent(true, routeData.SERVICE_LOCATION.name); + } +}