Files
emailtemplate.it/public/assets/js/account.js
2026-01-12 23:57:46 +01:00

32 lines
958 B
JavaScript

import { apiAction } from './api.js';
import { initUserPanel, initAccountPage } from './ui-user.js';
import { initBridgeSetupPage } from './bridge-setup-page.js';
import { mountLogoutButton, ensureFloatingLogout } from './ui-auth.js';
async function ensureAuthenticated() {
try {
const me = await apiAction('auth.me', { method: 'GET' });
if (!me?.ok || !me?.user) {
if (!window.DISABLE_AUTH_REDIRECT) {
window.location.href = '/login.php';
}
return false;
}
window.__currentUser = me.user;
document.documentElement.classList.remove('auth-pending');
return true;
} catch {
return false;
}
}
document.addEventListener('DOMContentLoaded', async () => {
const ok = await ensureAuthenticated();
if (!ok) return;
initUserPanel();
initAccountPage();
initBridgeSetupPage();
mountLogoutButton('#btn-logout', { redirect: '/login.php' });
ensureFloatingLogout({ redirect: '/login.php' });
});