mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
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
This commit is contained in:
parent
3bed117b57
commit
e20e5775a6
1 changed files with 4 additions and 2 deletions
|
@ -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',
|
||||
|
|
Loading…
Add table
Reference in a new issue