fix: reload viewer page after login
This commit is contained in:
@@ -147,6 +147,7 @@
|
|||||||
try {
|
try {
|
||||||
const res = await fetch('/api/login', {
|
const res = await fetch('/api/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
credentials: 'same-origin',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ role: 'admin', password: input.value })
|
body: JSON.stringify({ role: 'admin', password: input.value })
|
||||||
});
|
});
|
||||||
|
|||||||
+5
-5
@@ -315,7 +315,7 @@
|
|||||||
|
|
||||||
async function loadAppConfig() {
|
async function loadAppConfig() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/app-config');
|
const res = await fetch('/api/app-config', { credentials: 'same-origin' });
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
appConfig.publicBaseUrl = (data.publicBaseUrl || '').replace(/\/+$/, '');
|
appConfig.publicBaseUrl = (data.publicBaseUrl || '').replace(/\/+$/, '');
|
||||||
@@ -326,7 +326,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkSession() {
|
async function checkSession() {
|
||||||
const res = await fetch('/api/session');
|
const res = await fetch('/api/session', { credentials: 'same-origin' });
|
||||||
if (!res.ok) return false;
|
if (!res.ok) return false;
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
return data.authenticated && (data.role === 'viewer' || data.role === 'admin');
|
return data.authenticated && (data.role === 'viewer' || data.role === 'admin');
|
||||||
@@ -344,7 +344,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadHistory() {
|
async function loadHistory() {
|
||||||
const res = await fetch('/api/history');
|
const res = await fetch('/api/history', { credentials: 'same-origin' });
|
||||||
if (res.status === 401) {
|
if (res.status === 401) {
|
||||||
showLogin('请先输入访问密码。');
|
showLogin('请先输入访问密码。');
|
||||||
return;
|
return;
|
||||||
@@ -417,6 +417,7 @@
|
|||||||
try {
|
try {
|
||||||
const res = await fetch('/api/login', {
|
const res = await fetch('/api/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
credentials: 'same-origin',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ role: 'viewer', password: input.value })
|
body: JSON.stringify({ role: 'viewer', password: input.value })
|
||||||
});
|
});
|
||||||
@@ -424,8 +425,7 @@
|
|||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(data.error || '密码不正确');
|
throw new Error(data.error || '密码不正确');
|
||||||
}
|
}
|
||||||
showHistory();
|
window.location.href = data.redirectTo || '/sub';
|
||||||
await loadHistory();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error.textContent = e.message;
|
error.textContent = e.message;
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user