Stopped browser-auth editing src of auth-pages frame

refs #36

This removes the behaviour of forcing the `src` property to change when
opening the auth pages and insteads posts a message "asking" the auth
pages to update the location hash.
This commit is contained in:
Fabien O'Carroll 2019-07-09 18:28:32 +08:00
parent 550ea70c9c
commit 474c495331

View File

@ -11,6 +11,11 @@ module.exports = function layer2(options) {
container
});
function postMessage(frame, data) {
var origin = new URL(frame.getAttribute('src')).origin;
frame.contentWindow.postMessage(data, origin);
}
var loadAuth = loadFrame(authUrl, container).then(function (frame) {
frame.style.position = 'fixed';
frame.style.width = '100%';
@ -24,7 +29,7 @@ module.exports = function layer2(options) {
function openAuth(hash, query = '') {
return loadAuth.then(function (frame) {
return new Promise(function (resolve) {
frame.src = `${authUrl}#${hash}?${query}`;
postMessage(frame, {hash, query});
frame.style.display = 'block';
window.addEventListener('message', function messageListener(event) {
if (event.source !== frame.contentWindow) {