소스 검색

Fix logout for invalid sessions

KernelDeimos 1 년 전
부모
커밋
6f7264b60b
2개의 변경된 파일27개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 1
      src/helpers.js
  2. 24 1
      src/initgui.js

+ 3 - 1
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}));    
 }
 
 /**

+ 24 - 1
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;
                 }
             }