44 lines
1.7 KiB
PHP
44 lines
1.7 KiB
PHP
<?php
|
|
$pageTitle = isset($pageTitle) ? $pageTitle : 'WebGIS Poverty Mapping';
|
|
?>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= htmlspecialchars($pageTitle) ?></title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Space+Grotesk:wght@500;700&display=swap" rel="stylesheet" />
|
|
<link rel="stylesheet" href="css/base.css">
|
|
<link rel="stylesheet" href="css/layout.css">
|
|
<link rel="stylesheet" href="css/components.css">
|
|
<?php if (isset($pageCss) && $pageCss) { ?>
|
|
<link rel="stylesheet" href="<?= htmlspecialchars($pageCss) ?>">
|
|
<?php } ?>
|
|
|
|
<!-- Auth init: store user in window, dispatch event AFTER DOM is ready -->
|
|
<script>
|
|
// Fetch auth immediately (parallel with page load), but dispatch event
|
|
// only after DOMContentLoaded so all listeners are already attached.
|
|
window._authPromise = (async function () {
|
|
try {
|
|
const res = await fetch('api/me.php');
|
|
const data = await res.json();
|
|
if (data.status !== 'success') {
|
|
window.location.href = '?page=login';
|
|
return null;
|
|
}
|
|
window.currentUser = data.data;
|
|
return data.data;
|
|
} catch (e) {
|
|
window.location.href = '?page=login';
|
|
return null;
|
|
}
|
|
})();
|
|
|
|
// Once DOM is ready, resolve the auth and dispatch event
|
|
document.addEventListener('DOMContentLoaded', async function() {
|
|
const user = await window._authPromise;
|
|
if (!user) return; // already redirecting
|
|
document.dispatchEvent(new CustomEvent('auth-ready', { detail: user }));
|
|
});
|
|
</script>
|