improve behaviour when logging out of webui
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build / build (pull_request) Successful in 1m8s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build / build (pull_request) Successful in 1m8s
				
			This commit is contained in:
		
							parent
							
								
									4d972f2ead
								
							
						
					
					
						commit
						80d06bca35
					
				@ -97,7 +97,7 @@ export const stopWebServer = async (): Promise<void> => {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
interface IWsCustomData extends ws {
 | 
			
		||||
    accountId: string;
 | 
			
		||||
    accountId?: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
interface IWsMsgFromClient {
 | 
			
		||||
@ -106,6 +106,7 @@ interface IWsMsgFromClient {
 | 
			
		||||
        password: string;
 | 
			
		||||
        isRegister: boolean;
 | 
			
		||||
    };
 | 
			
		||||
    logout?: boolean;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
interface IWsMsgToClient {
 | 
			
		||||
@ -173,6 +174,9 @@ const wsOnConnect = (ws: ws, _req: http.IncomingMessage): void => {
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (data.logout) {
 | 
			
		||||
            (ws as IWsCustomData).accountId = undefined;
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -37,7 +37,7 @@
 | 
			
		||||
                <li class="nav-item dropdown user-dropdown">
 | 
			
		||||
                    <button class="nav-link dropdown-toggle displayname" data-bs-toggle="dropdown" aria-expanded="false"></button>
 | 
			
		||||
                    <ul class="dropdown-menu dropdown-menu-end">
 | 
			
		||||
                        <li><a class="dropdown-item" href="/webui/" onclick="logout();" data-loc="navbar_logout"></a></li>
 | 
			
		||||
                        <li><a class="dropdown-item" href="/webui/" onclick="doLogout();" data-loc="navbar_logout"></a></li>
 | 
			
		||||
                        <li><hr class="dropdown-divider"></li>
 | 
			
		||||
                        <li><a class="dropdown-item" href="#" onclick="event.preventDefault();renameAccount();" data-loc="navbar_renameAccount"></a></li>
 | 
			
		||||
                        <li><a class="dropdown-item" href="#" onclick="event.preventDefault();deleteAccount();" data-loc="navbar_deleteAccount"></a></li>
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@
 | 
			
		||||
let auth_pending = false,
 | 
			
		||||
    did_initial_auth = false;
 | 
			
		||||
const sendAuth = isRegister => {
 | 
			
		||||
    if (localStorage.getItem("email") && localStorage.getItem("password")) {
 | 
			
		||||
        auth_pending = true;
 | 
			
		||||
        window.ws.send(
 | 
			
		||||
            JSON.stringify({
 | 
			
		||||
@ -21,14 +22,13 @@ const sendAuth = isRegister => {
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function openWebSocket() {
 | 
			
		||||
    window.ws = new WebSocket("/custom/ws");
 | 
			
		||||
    window.ws.onopen = () => {
 | 
			
		||||
        if (localStorage.getItem("email") && localStorage.getItem("password")) {
 | 
			
		||||
        sendAuth(false);
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    window.ws.onmessage = e => {
 | 
			
		||||
        const msg = JSON.parse(e.data);
 | 
			
		||||
@ -115,6 +115,14 @@ function logout() {
 | 
			
		||||
    did_initial_auth = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function doLogout() {
 | 
			
		||||
    logout();
 | 
			
		||||
    if (window.ws) {
 | 
			
		||||
        // Unsubscribe from notifications about nonce invalidation
 | 
			
		||||
        window.ws.send(JSON.stringify({ logout: true }));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function renameAccount() {
 | 
			
		||||
    const newname = window.prompt(loc("code_changeNameConfirm"));
 | 
			
		||||
    if (newname) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user