Fix login issues with safe links

pull/1/head
yflory 4 years ago
parent 6b734e7a80
commit bbd101ec8a

@ -2273,7 +2273,7 @@ define([
var o = e.oldValue; var o = e.oldValue;
var n = e.newValue; var n = e.newValue;
if (!o && n) { if (!o && n) {
document.location.reload(); LocalStore.loginReload();
} else if (o && !n) { } else if (o && !n) {
LocalStore.logout(); LocalStore.logout();
} }

@ -129,6 +129,18 @@ define([
if (cb) { cb(); } if (cb) { cb(); }
}; };
var loginHandlers = [];
LocalStore.loginReload = function () {
loginHandlers.forEach(function (h) {
if (typeof (h) === "function") { h(); }
});
document.location.reload();
};
LocalStore.onLogin = function (h) {
if (typeof (h) !== "function") { return; }
if (loginHandlers.indexOf(h) !== -1) { return; }
loginHandlers.push(h);
};
LocalStore.onLogout = function (h) { LocalStore.onLogout = function (h) {
if (typeof (h) !== "function") { return; } if (typeof (h) !== "function") { return; }
if (logoutHandlers.indexOf(h) !== -1) { return; } if (logoutHandlers.indexOf(h) !== -1) { return; }

@ -511,7 +511,19 @@ define([
Cryptpad.onMetadataChanged(updateMeta); Cryptpad.onMetadataChanged(updateMeta);
sframeChan.onReg('EV_METADATA_UPDATE', updateMeta); sframeChan.onReg('EV_METADATA_UPDATE', updateMeta);
Utils.LocalStore.onLogin(function () {
var ohc = window.onhashchange;
window.onhashchange = function () {};
window.location.hash = currentPad.hash;
window.onhashchange = ohc;
ohc({reset: true});
});
Utils.LocalStore.onLogout(function () { Utils.LocalStore.onLogout(function () {
var ohc = window.onhashchange;
window.onhashchange = function () {};
window.location.hash = currentPad.hash;
window.onhashchange = ohc;
ohc({reset: true});
sframeChan.event('EV_LOGOUT'); sframeChan.event('EV_LOGOUT');
}); });

Loading…
Cancel
Save