user
This commit is contained in:
27
public/assets/js/account.js
Normal file
27
public/assets/js/account.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { apiAction } from './api.js';
|
||||
import { initUserPanel, initAccountPage } from './ui-user.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) {
|
||||
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();
|
||||
mountLogoutButton('#btn-logout', { redirect: '/login.php' });
|
||||
ensureFloatingLogout({ redirect: '/login.php' });
|
||||
});
|
||||
Reference in New Issue
Block a user