chore(webui): improve auth state management
All checks were successful
Build Docker image / docker-arm64 (push) Successful in 1m4s
Build / build (push) Successful in 1m1s
Build Docker image / docker-amd64 (push) Successful in 55s

This commit is contained in:
Sainan 2025-07-21 20:28:19 +02:00
parent c0ca9d9398
commit 41e3f0136f
2 changed files with 18 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import { GuildMember } from "@/src/models/guildModel";
import { Leaderboard } from "@/src/models/leaderboardModel";
import { deleteGuild } from "@/src/services/guildService";
import { Friendship } from "@/src/models/friendModel";
import { sendWsBroadcastTo } from "@/src/services/wsService";
export const deleteAccountController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
@ -36,5 +37,8 @@ export const deleteAccountController: RequestHandler = async (req, res) => {
Ship.deleteMany({ ShipOwnerId: accountId }),
Stats.deleteOne({ accountOwnerId: accountId })
]);
sendWsBroadcastTo(accountId, { logged_out: true });
res.end();
};

View File

@ -118,9 +118,16 @@ function doLogin() {
window.registerSubmit = false;
}
async function revalidateAuthz() {
await getWebSocket();
// We have a websocket connection, so authz should be good.
function revalidateAuthz() {
return new Promise(resolve => {
let interval;
interval = setInterval(() => {
if (ws_is_open && !auth_pending) {
clearInterval(interval);
resolve();
}
}, 10);
});
}
function logout() {
@ -2080,6 +2087,10 @@ single.getRoute("/webui/cheats").on("beforeload", function () {
})
.fail(res => {
if (res.responseText == "Log-in expired") {
if (ws_is_open && !auth_pending) {
console.warn("Credentials invalidated but the server didn't let us know");
sendAuth();
}
revalidateAuthz().then(() => {
if (single.getCurrentPath() == "/webui/cheats") {
single.loadRoute("/webui/cheats");