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 { 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();
|
||||
};
|
||||
|
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user