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',