From e96f114d40a7cba5e659c9dabebda774aa4feca5 Mon Sep 17 00:00:00 2001 From: Mees Hoogendoorn Date: Thu, 24 Feb 2022 10:50:07 +0100 Subject: [PATCH] fix(nuxt module): redirect 302 issue on apple devices (#1817) --- packages/nuxt-module/plugins/api-client.js | 19 +++++++++++++++++++ .../src/services/checkoutService.ts | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/nuxt-module/plugins/api-client.js b/packages/nuxt-module/plugins/api-client.js index 3790afe77..d94b1b171 100644 --- a/packages/nuxt-module/plugins/api-client.js +++ b/packages/nuxt-module/plugins/api-client.js @@ -23,6 +23,25 @@ export default async ({ app }, inject) => { if (!app.$cookies) { throw "Error cookie-universal-nuxt module is not applied in nuxt.config.js"; } + + /** + * get contextToken from sessionStorage when cookie lost in redirects + * https://github.com/vuestorefront/shopware-pwa/pull/1817 + */ + if (process.client && navigator?.userAgent.includes('WebKit')) { + if (!app.$cookies.get("sw-context-token") && typeof sessionStorage !== "undefined") { + app.$cookies.set( + "sw-context-token", + sessionStorage.getItem("sw-context-token"), + { + maxAge: 60 * 60 * 24 * 365, + sameSite: "Lax", + path: "/", + } + ) + } + sessionStorage.removeItem("sw-context-token") + } function getCookiesConfig(app) { return { diff --git a/packages/shopware-6-client/src/services/checkoutService.ts b/packages/shopware-6-client/src/services/checkoutService.ts index 88a417cbe..787133ee5 100644 --- a/packages/shopware-6-client/src/services/checkoutService.ts +++ b/packages/shopware-6-client/src/services/checkoutService.ts @@ -54,6 +54,16 @@ export async function handlePayment( if (!params?.orderId) { throw new Error("handlePayment method requires orderId"); } + + /** + * save contextToken in sessionStorage when using Webkit + * https://github.com/vuestorefront/shopware-pwa/pull/1817 + */ + if(navigator?.userAgent.includes('WebKit')){ + if (typeof sessionStorage !== "undefined") { + sessionStorage.setItem("sw-context-token", contextInstance?.config?.contextToken as string) + } + } const resp = await contextInstance.invoke.get( handlePaymentEndpoint(),