Skip to content

Commit

Permalink
fix(nuxt module): redirect 302 issue on apple devices (#1817)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeshoogendoorn authored Feb 24, 2022
1 parent d095445 commit e96f114
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/nuxt-module/plugins/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions packages/shopware-6-client/src/services/checkoutService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit e96f114

Please sign in to comment.