This commit is contained in:
2025-12-08 00:07:43 +01:00
parent 352ad4c512
commit b3f10164de
2 changed files with 10 additions and 12 deletions

View File

@@ -2,8 +2,6 @@ import { apiAction } from './api.js';
import { initUserPanel, initAccountPage } from './ui-user.js';
import { mountLogoutButton, ensureFloatingLogout } from './ui-auth.js';
const pageType = document.body?.dataset?.page || 'account';
async function ensureAuthenticated() {
try {
const me = await apiAction('auth.me', { method: 'GET' });
@@ -19,19 +17,9 @@ async function ensureAuthenticated() {
}
}
function ensureAccess() {
const role = (window.__currentUser?.role || '').toLowerCase();
if (pageType === 'admin' && role !== 'owner' && role !== 'admin') {
window.location.href = '/account.php';
return false;
}
return true;
}
document.addEventListener('DOMContentLoaded', async () => {
const ok = await ensureAuthenticated();
if (!ok) return;
if (!ensureAccess()) return;
initUserPanel();
initAccountPage();
mountLogoutButton('#btn-logout', { redirect: '/login.php' });