/* SoftSins - Supabase Configuration */ // Supabase configuration - Replace with your actual values const SUPABASE_URL = 'https://xboptgbvoqfwpszftoqc.supabase.co'; // Replace with: https://your-project-id.supabase.co const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inhib3B0Z2J2b3Fmd3BzemZ0b3FjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjM5MjAxNzYsImV4cCI6MjA3OTQ5NjE3Nn0.O1Ecitm-wOp7ZefaWZLiYD4Lp411jM0x-bCInYo2E2M'; // Replace with your anon key // Initialize Supabase client const supabase = window.supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY); // Authentication state management class SoftSinsAuth { constructor() { this.currentUser = null; this.isAuthenticated = false; // Check initial auth state this.checkAuthState(); // Listen for auth changes supabase.auth.onAuthStateChange((event, session) => { console.log('Auth state changed:', event, session); this.handleAuthStateChange(event, session); }); } async checkAuthState() { try { const { data: { session } } = await supabase.auth.getSession(); if (session) { this.currentUser = session.user; this.isAuthenticated = true; console.log('User is authenticated:', this.currentUser.email); this.updateNavigation(true); } else { this.currentUser = null; this.isAuthenticated = false; console.log('User is not authenticated'); this.updateNavigation(false); } } catch (error) { console.error('Error checking auth state:', error); this.isAuthenticated = false; this.updateNavigation(false); } } handleAuthStateChange(event, session) { if (event === 'SIGNED_IN') { this.currentUser = session.user; this.isAuthenticated = true; console.log('User signed in:', this.currentUser.email); this.updateNavigation(true); this.showSuccessMessage('Erfolgreich angemeldet!'); } else if (event === 'SIGNED_OUT') { this.currentUser = null; this.isAuthenticated = false; console.log('User signed out'); this.updateNavigation(false); this.showSuccessMessage('Erfolgreich abgemeldet!'); } else if (event === 'TOKEN_REFRESHED') { console.log('Token refreshed'); } } updateNavigation(isAuthenticated) { // Update navigation buttons (including NEUE_HOMEPAGE.html) const navButtons = document.querySelectorAll('.nav-cta a, .nav-cta-mobile a, .nav-menu li:last-child a'); navButtons.forEach(button => { if (isAuthenticated) { // User is logged in - show profile/logout button.textContent = 'Profil'; button.href = '#'; // Remove onclick attribute and add event listener button.removeAttribute('onclick'); // Clear existing event listeners by cloning const newButton = button.cloneNode(true); button.parentNode.replaceChild(newButton, button); newButton.addEventListener('click', (e) => { e.preventDefault(); this.showUserMenu(e.target); }); } else { // User is not logged in - show login button.textContent = 'Anmelden'; button.href = '#'; // Ensure onclick attribute is set button.setAttribute('onclick', 'openLoginModal(); return false;'); } }); } showUserMenu(button) { // Create user dropdown menu const existingMenu = document.querySelector('.user-dropdown'); if (existingMenu) { existingMenu.remove(); return; } // Make sure the parent container has relative positioning const navCta = button.closest('.nav-cta, .nav-cta-mobile, .nav-menu li'); if (navCta) { navCta.style.position = 'relative'; } const dropdown = document.createElement('div'); dropdown.className = 'user-dropdown'; // Check if this is NEUE_HOMEPAGE.html (simple nav-menu structure) const isNeueHomepage = button.closest('.nav-menu') && !button.closest('.nav-cta'); dropdown.style.cssText = ` position: absolute; top: calc(100% + 10px); ${isNeueHomepage ? 'right: 0' : 'right: 0'}; background: white; border: 1px solid #E8E8E8; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); z-index: 1000; min-width: 200px; `; dropdown.innerHTML = `