From 286cc08933909352ce3a1cccce66e0e19eafd870 Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Fri, 11 Aug 2023 16:02:30 -0700 Subject: [PATCH] fix: actions open in new link if in connect iframe --- web/store/account.ts | 102 ++++++++++++++++++++++++++---------------- web/store/callback.ts | 9 +++- web/store/purchase.ts | 54 +++++++++++++--------- web/store/server.ts | 1 + 4 files changed, 104 insertions(+), 62 deletions(-) diff --git a/web/store/account.ts b/web/store/account.ts index a15582eef..527f91583 100644 --- a/web/store/account.ts +++ b/web/store/account.ts @@ -30,57 +30,81 @@ export const useAccountStore = defineStore('account', () => { // Actions const recover = () => { console.debug('[accountStore.recover]'); - callbackStore.send(ACCOUNT_CALLBACK.toString(), [{ - server: { - ...serverStore.serverAccountPayload, - }, - type: 'recover', - }]); + callbackStore.send( + ACCOUNT_CALLBACK.toString(), + [{ + server: { + ...serverStore.serverAccountPayload, + }, + type: 'recover', + }], + serverStore.inIframe, + ); }; const replace = () => { console.debug('[accountStore.replace]'); - callbackStore.send(ACCOUNT_CALLBACK.toString(), [{ - server: { - ...serverStore.serverAccountPayload, - }, - type: 'replace', - }]); + callbackStore.send( + ACCOUNT_CALLBACK.toString(), + [{ + server: { + ...serverStore.serverAccountPayload, + }, + type: 'replace', + }], + serverStore.inIframe, + ); }; const signIn = () => { console.debug('[accountStore.signIn]'); - callbackStore.send(ACCOUNT_CALLBACK.toString(), [{ - server: { - ...serverStore.serverAccountPayload, - }, - type: 'signIn', - }]); + callbackStore.send( + ACCOUNT_CALLBACK.toString(), + [{ + server: { + ...serverStore.serverAccountPayload, + }, + type: 'signIn', + }], + serverStore.inIframe, + ); }; const signOut = () => { - console.debug('[accountStore.accountStore.signOut]'); - callbackStore.send(ACCOUNT_CALLBACK.toString(), [{ - server: { - ...serverStore.serverAccountPayload, - }, - type: 'signOut', - }]); + console.debug('[accountStore.signOut]'); + callbackStore.send( + ACCOUNT_CALLBACK.toString(), + [{ + server: { + ...serverStore.serverAccountPayload, + }, + type: 'signOut', + }], + serverStore.inIframe, + ); }; const trialExtend = () => { - console.debug('[accountStore.accountStore.trialExtend]'); - callbackStore.send(ACCOUNT_CALLBACK.toString(), [{ - server: { - ...serverStore.serverAccountPayload, - }, - type: 'trialExtend', - }]); + console.debug('[accountStore.trialExtend]'); + callbackStore.send( + ACCOUNT_CALLBACK.toString(), + [{ + server: { + ...serverStore.serverAccountPayload, + }, + type: 'trialExtend', + }], + serverStore.inIframe, + ); }; const trialStart = () => { - console.debug('[accountStore.accountStore.trialStart]'); - callbackStore.send(ACCOUNT_CALLBACK.toString(), [{ - server: { - ...serverStore.serverAccountPayload, - }, - type: 'trialStart', - }]); + console.debug('[accountStore.trialStart]'); + callbackStore.send( + ACCOUNT_CALLBACK.toString(), + [{ + server: { + ...serverStore.serverAccountPayload, + }, + type: 'trialStart', + }], + serverStore.inIframe, + ); }; /** * @description Update myservers.cfg for both Sign In & Sign Out diff --git a/web/store/callback.ts b/web/store/callback.ts index 2e261d84d..3252fcd86 100644 --- a/web/store/callback.ts +++ b/web/store/callback.ts @@ -114,8 +114,8 @@ export const useCallbackStoreGeneric = ( const encryptionKey = import.meta.env.VITE_CALLBACK_KEY; const defaultSendType = 'fromUpc'; - const send = (url: string, payload: SendPayloads, sendType?: 'fromUpc' | 'forUpc') => { - console.debug('[callback.send]'); + const send = (url: string, payload: SendPayloads, newTab: boolean = false, sendType?: 'fromUpc' | 'forUpc') => { + console.debug('[callback.send]', { url, payload, sendType, newTab }); try { const stringifiedData = JSON.stringify({ actions: [ @@ -129,6 +129,11 @@ export const useCallbackStoreGeneric = ( const destinationUrl = new URL(url); destinationUrl.searchParams.set('data', encodeURI(encryptedMessage)); console.debug('[callback.send]', encryptedMessage, destinationUrl); + + if (newTab) { + window.open(destinationUrl.toString(), '_blank'); + return; + } window.location.href = destinationUrl.toString(); } catch (error) { console.error(error); diff --git a/web/store/purchase.ts b/web/store/purchase.ts index da4a5ae43..61c2f60c7 100644 --- a/web/store/purchase.ts +++ b/web/store/purchase.ts @@ -15,31 +15,43 @@ export const usePurchaseStore = defineStore('purchase', () => { const serverStore = useServerStore(); const redeem = () => { - console.debug('[redeem]'); - callbackStore.send(PURCHASE_CALLBACK.toString(), [{ - server: { - ...serverStore.serverPurchasePayload, - }, - type: 'redeem', - }]); + console.debug('[serverStore.redeem]'); + callbackStore.send( + PURCHASE_CALLBACK.toString(), + [{ + server: { + ...serverStore.serverPurchasePayload, + }, + type: 'redeem', + }], + serverStore.inIframe, + ); }; const purchase = () => { - console.debug('[purchase]'); - callbackStore.send(PURCHASE_CALLBACK.toString(), [{ - server: { - ...serverStore.serverPurchasePayload, - }, - type: 'purchase', - }]); + console.debug('[serverStore.purchase]'); + callbackStore.send( + PURCHASE_CALLBACK.toString(), + [{ + server: { + ...serverStore.serverPurchasePayload, + }, + type: 'purchase', + }], + serverStore.inIframe, + ); }; const upgrade = () => { - console.debug('[upgrade]'); - callbackStore.send(PURCHASE_CALLBACK.toString(), [{ - server: { - ...serverStore.serverPurchasePayload, - }, - type: 'upgrade', - }]); + console.debug('[serverStore.upgrade]'); + callbackStore.send( + PURCHASE_CALLBACK.toString(), + [{ + server: { + ...serverStore.serverPurchasePayload, + }, + type: 'upgrade', + }], + serverStore.inIframe, + ); }; return { diff --git a/web/store/server.ts b/web/store/server.ts index 7187d0558..4237715df 100644 --- a/web/store/server.ts +++ b/web/store/server.ts @@ -876,6 +876,7 @@ export const useServerStore = defineStore('server', () => { deviceCount, expireTime, guid, + inIframe, locale, lanIp, name,