mirror of
https://github.com/HeyPuter/puter.git
synced 2026-03-18 02:32:25 -05:00
Fix logout for invalid sessions
This commit is contained in:
@@ -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}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user