관리자 세션 해제 시 런처 일반 화면 전환

This commit is contained in:
seo
2026-07-11 06:17:22 +09:00
parent 2106830a47
commit 6aef96ecdb
3 changed files with 25 additions and 4 deletions
+23 -2
View File
@@ -1,5 +1,6 @@
const shortcut = document.getElementById('findMyShortcut');
let failIndex = 0;
let lastRenderedAdmin = null;
const apiUrl = '/custom/launcher/api.php';
const PIN_LENGTH = 4;
@@ -83,6 +84,7 @@ async function renderIcons() {
}
const isAdmin = !!session.admin;
lastRenderedAdmin = isAdmin;
const items = isAdmin ? adminIconItems : userIconItems;
shortcut.className = `find-container ${isAdmin ? 'launcher-admin-grid' : ''}`;
shortcut.innerHTML = '';
@@ -119,8 +121,12 @@ async function renderIcons() {
}
async function hasAdminSession() {
const session = await getSession();
return !!session.admin;
try {
const session = await fetch(`${apiUrl}?adminSession=1`, { credentials: 'same-origin' }).then(res => res.json());
return !!session.admin;
} catch (_) {
return false;
}
}
async function getSession() {
@@ -149,6 +155,21 @@ async function requireAccess(nextAction) {
showPasswordForm(nextAction);
}
async function refreshAdminModeIfNeeded() {
if (lastRenderedAdmin !== true) return;
const isAdmin = await hasAdminSession();
if (!isAdmin) {
await renderIcons();
}
}
document.addEventListener('visibilitychange', () => {
if (!document.hidden) {
refreshAdminModeIfNeeded();
}
});
window.addEventListener('focus', refreshAdminModeIfNeeded);
function renderLoginBlocked(session = {}) {
shortcut.className = 'launcher-blocked';
shortcut.innerHTML = '';