update function login
Some checks failed
Test / test (push) Has been cancelled

This commit is contained in:
2026-06-16 09:57:55 +07:00
parent 6fa15b69e7
commit 9aee5f4100
19 changed files with 2272 additions and 64 deletions

View File

@@ -188,7 +188,7 @@
async function loadStoreFromBackend() {
try {
const res = await fetch("/api/missions");
const res = await fetch("/api/missions", { credentials: "include" });
if (!res.ok) return false;
const data = await res.json();
if (Array.isArray(data.missions)) store.missions = data.missions;
@@ -209,6 +209,7 @@
async function syncStoreToBackend() {
try {
await fetch("/api/missions", {
credentials: "include",
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ missions: store.missions, groups: store.groups }),
@@ -396,7 +397,11 @@
}
async function missionApi(path, opts = {}) {
if (window.AuthApp && !window.AuthApp.isReady()) {
throw new Error("not authenticated");
}
const res = await fetch(path, {
credentials: "include",
headers: { "Content-Type": "application/json", ...(opts.headers || {}) },
...opts,
});
@@ -479,6 +484,7 @@
}
async function refreshQueue() {
if (window.AuthApp && !window.AuthApp.isReady()) return;
try {
const data = await missionApi("/api/mission_queue");
store.queue = Array.isArray(data.queue) ? data.queue : [];
@@ -486,6 +492,7 @@
renderQueuePanel();
notifyQueueUpdate();
} catch (e) {
if (String(e.message || "").includes("not authenticated")) return;
if (missionQueueRunnerEl) missionQueueRunnerEl.textContent = `Không tải được queue: ${e.message}`;
}
}
@@ -706,6 +713,7 @@
}
function startQueuePoll() {
if (window.AuthApp && !window.AuthApp.isReady()) return;
stopQueuePoll();
refreshQueue();
store.queuePollTimer = setInterval(refreshQueue, 1500);
@@ -1368,5 +1376,10 @@
},
};
init();
function boot() {
init();
}
if (window.AuthApp?.isReady()) boot();
else window.addEventListener("lm:auth-ready", boot, { once: true });
window.addEventListener("lm:auth-logout", stopQueuePoll);
})();