mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Allowed auth-pages to update location from message
refs #36 This will allow the members-browser-auth library to post messages to the auth-pages iframe, asking it to update the location from inside the frame.
This commit is contained in:
parent
f89677b1ce
commit
550ea70c9c
1 changed files with 11 additions and 0 deletions
|
@ -5,6 +5,8 @@ export default class Pages extends Component {
|
|||
constructor(props) {
|
||||
super(props);
|
||||
this.state = this.getStateFromBrowser();
|
||||
this.parentOrigin = new URL(document.referrer).origin;
|
||||
window.addEventListener('message', (event) => this.onReceiveMessage(event));
|
||||
window.addEventListener("hashchange", () => this.onHashChange(), false);
|
||||
this.handleChange = props.onChange || (() => { });
|
||||
}
|
||||
|
@ -18,6 +20,15 @@ export default class Pages extends Component {
|
|||
};
|
||||
}
|
||||
|
||||
onReceiveMessage(event) {
|
||||
if (event.origin !== this.parentOrigin) {
|
||||
return;
|
||||
}
|
||||
const {hash, query} = event.data;
|
||||
const newHash = `${hash}?${query}`;
|
||||
window.location.hash = newHash;
|
||||
}
|
||||
|
||||
onHashChange() {
|
||||
this.setState(this.getStateFromBrowser());
|
||||
this.handleChange();
|
||||
|
|
Loading…
Add table
Reference in a new issue