chore(webui): improve auth state management
This commit is contained in:
parent
c0ca9d9398
commit
41e3f0136f
@ -11,6 +11,7 @@ import { GuildMember } from "@/src/models/guildModel";
|
|||||||
import { Leaderboard } from "@/src/models/leaderboardModel";
|
import { Leaderboard } from "@/src/models/leaderboardModel";
|
||||||
import { deleteGuild } from "@/src/services/guildService";
|
import { deleteGuild } from "@/src/services/guildService";
|
||||||
import { Friendship } from "@/src/models/friendModel";
|
import { Friendship } from "@/src/models/friendModel";
|
||||||
|
import { sendWsBroadcastTo } from "@/src/services/wsService";
|
||||||
|
|
||||||
export const deleteAccountController: RequestHandler = async (req, res) => {
|
export const deleteAccountController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
@ -36,5 +37,8 @@ export const deleteAccountController: RequestHandler = async (req, res) => {
|
|||||||
Ship.deleteMany({ ShipOwnerId: accountId }),
|
Ship.deleteMany({ ShipOwnerId: accountId }),
|
||||||
Stats.deleteOne({ accountOwnerId: accountId })
|
Stats.deleteOne({ accountOwnerId: accountId })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
sendWsBroadcastTo(accountId, { logged_out: true });
|
||||||
|
|
||||||
res.end();
|
res.end();
|
||||||
};
|
};
|
||||||
|
@ -118,9 +118,16 @@ function doLogin() {
|
|||||||
window.registerSubmit = false;
|
window.registerSubmit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function revalidateAuthz() {
|
function revalidateAuthz() {
|
||||||
await getWebSocket();
|
return new Promise(resolve => {
|
||||||
// We have a websocket connection, so authz should be good.
|
let interval;
|
||||||
|
interval = setInterval(() => {
|
||||||
|
if (ws_is_open && !auth_pending) {
|
||||||
|
clearInterval(interval);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}, 10);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
@ -2080,6 +2087,10 @@ single.getRoute("/webui/cheats").on("beforeload", function () {
|
|||||||
})
|
})
|
||||||
.fail(res => {
|
.fail(res => {
|
||||||
if (res.responseText == "Log-in expired") {
|
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(() => {
|
revalidateAuthz().then(() => {
|
||||||
if (single.getCurrentPath() == "/webui/cheats") {
|
if (single.getCurrentPath() == "/webui/cheats") {
|
||||||
single.loadRoute("/webui/cheats");
|
single.loadRoute("/webui/cheats");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user