/** * Admin Authentication Module * Handles user authentication, session management, and admin authorization */ // Check if user is authenticated as admin async function checkAdminAuth() { try { const response = await fetch('/api/auth/check'); const data = await response.json(); console.log('Admin auth check result:', data); if (!data.authenticated || !data.user?.isAdmin) { console.log('Redirecting to login - not authenticated or not admin'); window.location.href = '/login.html'; return; } console.log('User is authenticated as admin:', data.user); // Display admin info (desktop) const adminInfoEl = document.getElementById('admin-info'); if (adminInfoEl) { adminInfoEl.innerHTML = ` 👤 ${window.adminCore.escapeHtml(data.user.email)} `; // Add logout event listener const logoutBtn = document.getElementById('logout-btn'); if (logoutBtn) { logoutBtn.addEventListener('click', handleLogout); } } // Display admin info (mobile) const mobileAdminInfo = document.getElementById('mobile-admin-info'); if (mobileAdminInfo) { mobileAdminInfo.innerHTML = `