This commit is contained in:
dekun
2026-05-30 11:57:00 +08:00
parent 4c4af4a464
commit 8ffe46a344
6 changed files with 165 additions and 14 deletions
+25 -2
View File
@@ -41,11 +41,34 @@
const userInput = document.getElementById("login-username");
const params = new URLSearchParams(location.search);
const next = params.get("next") || "/monitor";
const inFrame = window.self !== window.top;
function gotoAfterLogin(token, dest) {
const target = dest.startsWith("/") ? dest : "/monitor";
if (token && inFrame) {
const q = new URLSearchParams({ token, next: target });
const embedUrl = "/embed-auth?" + q.toString();
try {
window.parent.postMessage(
{
type: "hub:login-ok",
session_token: token,
next: target,
embed_auth_url: location.origin + embedUrl,
},
"*"
);
} catch (_) {}
location.replace(embedUrl);
return;
}
location.href = target;
}
fetch("/api/auth/status")
.then((r) => r.json())
.then((s) => {
if (!s.required || s.logged_in) location.href = next;
if (!s.required || s.logged_in) gotoAfterLogin(null, next);
if (s.username_hint && !userInput.value) userInput.value = s.username_hint;
})
.catch(() => {});
@@ -63,7 +86,7 @@
});
const j = await r.json().catch(() => ({}));
if (r.ok && j.ok) {
location.href = next.startsWith("/") ? next : "/monitor";
gotoAfterLogin(j.session_token || null, next);
return;
}
err.textContent = j.detail || j.msg || "用户名或密码错误";