Merge pull request #61 from Jah-yee/fix/issue-54-unauthorized

fix: avoid 401 Unauthorized on first page load (fixes #54)
This commit is contained in:
ringhyacinth 2026-03-06 14:13:26 +08:00 committed by GitHub
commit 8ac5b51c3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View file

@ -4182,6 +4182,7 @@ function toggleBrokerPanel() {
bindAssetDrawerBackgroundDeselect();
await ensureGeminiConfigLoaded();
if (assetDrawerAuthed) {
await applySavedPositionOverrides();
await refreshAssetDrawerList();
await renderHomeFavorites(false);
bindDrawerFileMeta();
@ -4212,6 +4213,7 @@ function toggleBrokerPanel() {
bindAssetDrawerBackgroundDeselect();
await ensureGeminiConfigLoaded();
if (assetDrawerAuthed) {
await applySavedPositionOverrides();
await refreshAssetDrawerList();
await renderHomeFavorites(false);
bindDrawerFileMeta();
@ -4835,7 +4837,15 @@ function toggleBrokerPanel() {
// 启动 Phaser 游戏
new Phaser.Game(config);
setTimeout(() => { applySavedPositionOverrides(); }, 600);
setTimeout(async () => {
try {
const authRes = await fetch('/assets/auth/status', { cache: 'no-store' });
const authData = await authRes.json();
if (authData && authData.ok && authData.authed) {
await applySavedPositionOverrides();
}
} catch (e) {}
}, 600);
}
function preload() {

View file

@ -3300,6 +3300,7 @@ function toggleBrokerPanel() {
bindAssetDrawerBackgroundDeselect();
await ensureGeminiConfigLoaded();
if (assetDrawerAuthed) {
await applySavedPositionOverrides();
await refreshAssetDrawerList();
await renderHomeFavorites(false);
bindDrawerFileMeta();
@ -3925,7 +3926,15 @@ function toggleBrokerPanel() {
console.warn('flowers 规格探测失败,使用默认 65x65', e);
}
applySavedPositionOverrides();
// Only fetch /assets/positions and /assets/defaults when user is authed,
// to avoid 401 Unauthorized on first load for new visitors (issue #54).
try {
const authRes = await fetch('/assets/auth/status', { cache: 'no-store' });
const authData = await authRes.json();
if (authData && authData.ok && authData.authed) {
await applySavedPositionOverrides();
}
} catch (e) {}
}, 600);
}