Show management only to site admins

This commit is contained in:
seo
2026-06-12 15:38:09 +09:00
parent 8145dc6938
commit baeccf9d58
3 changed files with 21 additions and 3 deletions
+14 -1
View File
@@ -30,7 +30,7 @@ const iconItems = [
}
];
function renderIcons() {
async function renderIcons() {
shortcut.className = 'find-container';
shortcut.innerHTML = '';
@@ -53,6 +53,10 @@ function renderIcons() {
shortcut.appendChild(div);
});
if (!await hasAdminSession()) {
return;
}
const manage = document.createElement('button');
manage.type = 'button';
manage.className = 'launcher-manage';
@@ -61,6 +65,15 @@ function renderIcons() {
shortcut.appendChild(manage);
}
async function hasAdminSession() {
try {
const session = await fetch(`${apiUrl}?adminSession=1`, { credentials: 'same-origin' }).then(res => res.json());
return !!session.admin;
} catch (_) {
return false;
}
}
async function requireAccess(nextAction) {
try {
const session = await fetch(`${apiUrl}?session=1`, { credentials: 'same-origin' }).then(res => res.json());