返回提交历史
Modified
src/controllers/custom/deleteAccountController.ts
+4
-0
Modified
static/webui/script.js
+14
-3
XFEstudio/XFESpaceNinjaServer
chore(webui): improve auth state management
41e3f013
代码差异
2 个文件
+18
-3
@@ -11,6 +11,7 @@ import { GuildMember } from "@/src/models/guildModel";
11
11
import { Leaderboard } from "@/src/models/leaderboardModel";
12
12
import { deleteGuild } from "@/src/services/guildService";
13
13
import { Friendship } from "@/src/models/friendModel";
14
import { sendWsBroadcastTo } from "@/src/services/wsService";
14
15
15
16
export const deleteAccountController: RequestHandler = async (req, res) => {
16
17
const accountId = await getAccountIdForRequest(req);
@@ -36,5 +37,8 @@ export const deleteAccountController: RequestHandler = async (req, res) => {
36
37
Ship.deleteMany({ ShipOwnerId: accountId }),
37
38
Stats.deleteOne({ accountOwnerId: accountId })
38
39
]);
40
41
sendWsBroadcastTo(accountId, { logged_out: true });
42
39
43
res.end();
40
44
};
@@ -118,9 +118,16 @@ function doLogin() {
118
118
window.registerSubmit = false;
119
119
}
120
120
121
async function revalidateAuthz() {
122
await getWebSocket();
123
// We have a websocket connection, so authz should be good.
121
function revalidateAuthz() {
122
return new Promise(resolve => {
123
let interval;
124
interval = setInterval(() => {
125
if (ws_is_open && !auth_pending) {
126
clearInterval(interval);
127
resolve();
128
}
129
}, 10);
130
});
124
131
}
125
132
126
133
function logout() {
@@ -2080,6 +2087,10 @@ single.getRoute("/webui/cheats").on("beforeload", function () {
2080
2087
})
2081
2088
.fail(res => {
2082
2089
if (res.responseText == "Log-in expired") {
2090
if (ws_is_open && !auth_pending) {
2091
console.warn("Credentials invalidated but the server didn't let us know");
2092
sendAuth();
2093
}
2083
2094
revalidateAuthz().then(() => {
2084
2095
if (single.getCurrentPath() == "/webui/cheats") {
2085
2096
single.loadRoute("/webui/cheats");