logo

Seminars & Workshops

Educational and career development events

Third Eye

Third Eye Activation Event for Kids

Feedback of our Sadhakas

// Check authentication status and show/hide dashboard icon async function checkAuthAndShowDashboard() { try { const apiBase = window.API_BASE_URL || '/api'; const response = await fetch(`${apiBase}/auth/check`, { method: 'GET', credentials: 'include', headers: { 'Content-Type': 'application/json', } }); const data = await response.json(); const dashboardNavItem = document.getElementById('dashboardNavItem'); if (data.ok && data.user) { // User is authenticated - show dashboard icon if (dashboardNavItem) { dashboardNavItem.style.display = 'list-item'; } } else { // User is not authenticated - hide dashboard icon if (dashboardNavItem) { dashboardNavItem.style.display = 'none'; } } } catch (error) { console.error('Error checking authentication for dashboard icon:', error); // On error, hide the icon to be safe const dashboardNavItem = document.getElementById('dashboardNavItem'); if (dashboardNavItem) { dashboardNavItem.style.display = 'none'; } } } // Handle dashboard icon click - navigate to appropriate dashboard based on role async function handleDashboardClick(event) { event.preventDefault(); try { const response = await fetch('/api/auth/check', { method: 'GET', credentials: 'include', headers: { 'Content-Type': 'application/json', } }); const data = await response.json(); if (data.ok && data.user) { const role = data.user.role; const userRole = String(role || '').toLowerCase(); // Navigate based on role (same logic as NavBar.tsx) if (userRole.startsWith('org')) { // Org roles go to dashboard window.location.href = '/dashboard'; } else { switch (userRole) { case 'superadmin': window.location.href = '/superadmin'; break; case 'admin': window.location.href = '/admin'; break; case 'vendor': window.location.href = '/vendor'; break; case 'student': window.location.href = '/dashboard'; break; default: window.location.href = '/dashboard'; } } } else { // User is not authenticated, redirect to login window.location.href = '/login?returnUrl=/home'; } } catch (error) { console.error('Error navigating to dashboard:', error); // On error, redirect to login window.location.href = '/login?returnUrl=/home'; } } // Call checkAuthAndShowDashboard when page loads window.addEventListener('DOMContentLoaded', checkAuthAndShowDashboard);