From 61c2a0c00461d2e6709f9d4029bc833be81fc58d Mon Sep 17 00:00:00 2001 From: jocayn <1579649885@qq.com> Date: Sat, 13 Jun 2026 17:21:17 +0800 Subject: [PATCH] fix: reload viewer page after login --- public/login.html | 1 + public/viewer.html | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/public/login.html b/public/login.html index d1da14d..0503890 100644 --- a/public/login.html +++ b/public/login.html @@ -147,6 +147,7 @@ try { const res = await fetch('/api/login', { method: 'POST', + credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ role: 'admin', password: input.value }) }); diff --git a/public/viewer.html b/public/viewer.html index a73d192..4fe9c87 100644 --- a/public/viewer.html +++ b/public/viewer.html @@ -315,7 +315,7 @@ async function loadAppConfig() { try { - const res = await fetch('/api/app-config'); + const res = await fetch('/api/app-config', { credentials: 'same-origin' }); if (res.ok) { const data = await res.json(); appConfig.publicBaseUrl = (data.publicBaseUrl || '').replace(/\/+$/, ''); @@ -326,7 +326,7 @@ } async function checkSession() { - const res = await fetch('/api/session'); + const res = await fetch('/api/session', { credentials: 'same-origin' }); if (!res.ok) return false; const data = await res.json(); return data.authenticated && (data.role === 'viewer' || data.role === 'admin'); @@ -344,7 +344,7 @@ } async function loadHistory() { - const res = await fetch('/api/history'); + const res = await fetch('/api/history', { credentials: 'same-origin' }); if (res.status === 401) { showLogin('请先输入访问密码。'); return; @@ -417,6 +417,7 @@ try { const res = await fetch('/api/login', { method: 'POST', + credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ role: 'viewer', password: input.value }) }); @@ -424,8 +425,7 @@ if (!res.ok) { throw new Error(data.error || '密码不正确'); } - showHistory(); - await loadHistory(); + window.location.href = data.redirectTo || '/sub'; } catch (e) { error.textContent = e.message; } finally {