From bbd101ec8a4c5308c4a199abfdc22de9794519ee Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 5 Aug 2020 15:03:06 +0200 Subject: [PATCH] Fix login issues with safe links --- www/common/cryptpad-common.js | 2 +- www/common/outer/local-store.js | 12 ++++++++++++ www/common/sframe-common-outer.js | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 71848e36d..e027738ad 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -2273,7 +2273,7 @@ define([ var o = e.oldValue; var n = e.newValue; if (!o && n) { - document.location.reload(); + LocalStore.loginReload(); } else if (o && !n) { LocalStore.logout(); } diff --git a/www/common/outer/local-store.js b/www/common/outer/local-store.js index 8c39e8e9e..fbda718d4 100644 --- a/www/common/outer/local-store.js +++ b/www/common/outer/local-store.js @@ -129,6 +129,18 @@ define([ 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) { if (typeof (h) !== "function") { return; } if (logoutHandlers.indexOf(h) !== -1) { return; } diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 7253d8f1a..61cc1e694 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -511,7 +511,19 @@ define([ Cryptpad.onMetadataChanged(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 () { + var ohc = window.onhashchange; + window.onhashchange = function () {}; + window.location.hash = currentPad.hash; + window.onhashchange = ohc; + ohc({reset: true}); sframeChan.event('EV_LOGOUT'); });