mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
54560050c6
refs https://github.com/TryGhost/Ghost/issues/10886 Since updating the static pages, the auth pages would be broken, this updates them to correctly parse and load the static urls.
61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
import {Component} from 'preact';
|
|
|
|
const gatewayProtocol = require('@tryghost/members-gateway-protocol');
|
|
|
|
export default class MembersProvider extends Component {
|
|
constructor() {
|
|
super();
|
|
this.setGatewayFrame = gatewayFrame => this.gatewayFrame = gatewayFrame;
|
|
this.ready = new Promise((resolve) => {
|
|
this.setReady = resolve;
|
|
});
|
|
this.gateway = null;
|
|
}
|
|
|
|
getChildContext() {
|
|
return {
|
|
members: {
|
|
createSubscription: this.createMethod('createSubscription'),
|
|
signin: this.createMethod('signin'),
|
|
signup: this.createMethod('signup'),
|
|
requestPasswordReset: this.createMethod('requestPasswordReset'),
|
|
resetPassword: this.createMethod('resetPassword'),
|
|
getConfig: this.createMethod('getConfig')
|
|
}
|
|
};
|
|
}
|
|
|
|
render({apiUrl, children}) {
|
|
const src = `${apiUrl}/static/gateway`;
|
|
return (
|
|
<div>
|
|
{ children }
|
|
<iframe src={src} ref={this.setGatewayFrame} id="members-gateway" style="display: none;"/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
componentDidMount() {
|
|
const gatewayFrame = this.gatewayFrame;
|
|
gatewayFrame.addEventListener('load', () => {
|
|
this.gateway = gatewayProtocol(gatewayFrame);
|
|
this.setReady();
|
|
});
|
|
}
|
|
|
|
createMethod(method) {
|
|
return (options) => {
|
|
return this.ready.then(() => {
|
|
return new Promise((resolve, reject) => {
|
|
this.gateway.call(method, options, (err, successful) => {
|
|
if (err || !successful) {
|
|
reject(err || !successful);
|
|
}
|
|
resolve(successful);
|
|
});
|
|
});
|
|
});
|
|
};
|
|
}
|
|
}
|