improve behaviour when logging out of webui
All checks were successful
Build / build (pull_request) Successful in 1m8s

This commit is contained in:
Sainan 2025-06-21 14:27:35 +02:00
parent 4d972f2ead
commit 80d06bca35
3 changed files with 27 additions and 15 deletions

View File

@ -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;
}
});
};

View File

@ -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>

View File

@ -11,24 +11,24 @@
let auth_pending = false,
did_initial_auth = false;
const sendAuth = isRegister => {
auth_pending = true;
window.ws.send(
JSON.stringify({
auth: {
email: localStorage.getItem("email"),
password: wp.encSync(localStorage.getItem("password")),
isRegister
}
})
);
if (localStorage.getItem("email") && localStorage.getItem("password")) {
auth_pending = true;
window.ws.send(
JSON.stringify({
auth: {
email: localStorage.getItem("email"),
password: wp.encSync(localStorage.getItem("password")),
isRegister
}
})
);
}
};
function openWebSocket() {
window.ws = new WebSocket("/custom/ws");
window.ws.onopen = () => {
if (localStorage.getItem("email") && localStorage.getItem("password")) {
sendAuth(false);
}
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) {