From 6f7264b60bc21eaf6d100c6ec8dda4eaebc7d7c3 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Tue, 2 Apr 2024 04:19:12 -0400 Subject: [PATCH] Fix logout for invalid sessions --- src/helpers.js | 4 +++- src/initgui.js | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index a888cbeb4..5eeb2cbb9 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -738,7 +738,9 @@ window.sendWindowWillCloseMsg = function(iframe_element) { } window.logout = ()=>{ - document.dispatchEvent(new Event("logout", { bubbles: true})); + console.log('DISP LOGOUT EVENT'); + $(document).trigger('logout'); + // document.dispatchEvent(new Event("logout", { bubbles: true})); } /** diff --git a/src/initgui.js b/src/initgui.js index e285f06df..3e5f340e7 100644 --- a/src/initgui.js +++ b/src/initgui.js @@ -292,6 +292,29 @@ window.initgui = async function(){ window.history.pushState(null, document.title, '/'); } + /** + * Logout without showing confirmation or "Save Account" action, + * and without authenticating with the server. + */ + const bad_session_logout = async () => { + try { + // TODO: i18n + await UIAlert({ + message: 'Your session is invalid. You will be logged out.' + }); + // clear local storage + localStorage.clear(); + // reload the page + window.location.reload(); + }catch(e){ + // TODO: i18n + await UIAlert({ + message: 'Session is invalid and logout failed; ' + + 'please clear local storage manually.' + }); + } + }; + // ------------------------------------------------------------------------------------- // Authed // ------------------------------------------------------------------------------------- @@ -302,7 +325,7 @@ window.initgui = async function(){ whoami = await puter.os.user(); }catch(e){ if(e.status === 401){ - logout(); + bad_session_logout(); return; } }