From e20e5775a630160f764ab91094eb9e5eec7a299a Mon Sep 17 00:00:00 2001 From: Aileen Nowak Date: Thu, 20 May 2021 16:15:29 +1200 Subject: [PATCH] Fixed requesting subscription before sending token no issue - The Ghost(Pro) billing app would request a token once mounted to which Ghost sends the response to - Before, we wouldn't wait for the token to be sent and request subscription information from the Ghost(Pro) app straight away, which resulted in another token request (because it's not there yet) - This change will wait for the token to be sent before requesting subscription information from the Ghost(Pro) app to avoid duplicated requests to our servers --- ghost/admin/app/components/gh-billing-iframe.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ghost/admin/app/components/gh-billing-iframe.js b/ghost/admin/app/components/gh-billing-iframe.js index 96b6b65a2a..6c30e6be11 100644 --- a/ghost/admin/app/components/gh-billing-iframe.js +++ b/ghost/admin/app/components/gh-billing-iframe.js @@ -12,11 +12,13 @@ export default Component.extend({ this.billing.getBillingIframe().src = this.billing.getIframeURL(); window.addEventListener('message', (event) => { + let token; + if (event && event.data && event.data.request === 'token') { const ghostIdentityUrl = this.get('ghostPaths.url').api('identities'); this.ajax.request(ghostIdentityUrl).then((response) => { - const token = response && response.identities && response.identities[0] && response.identities[0].token; + token = response && response.identities && response.identities[0] && response.identities[0].token; this.billing.getBillingIframe().contentWindow.postMessage({ request: 'token', response: token @@ -25,7 +27,7 @@ export default Component.extend({ // NOTE: the handler is placed here to avoid additional logic to check if iframe has loaded // receiving a 'token' request is an indication that page is ready - if (!fetchingSubscription && !this.billing.get('subscription')) { + if (!fetchingSubscription && !this.billing.get('subscription') && token) { fetchingSubscription = true; this.billing.getBillingIframe().contentWindow.postMessage({ query: 'getSubscription',