diff --git a/src/components/Auth/AuthInitializer.tsx b/src/components/Auth/AuthInitializer.tsx index d06cf42..0dc59af 100644 --- a/src/components/Auth/AuthInitializer.tsx +++ b/src/components/Auth/AuthInitializer.tsx @@ -17,6 +17,7 @@ const AuthInitializer: React.FC = ({ children }) => { const isAuthenticated = useAppSelector(selectIsAuthenticated); useEffect(() => { + console.log('AuthInitializer effect - isAuthenticated:', isAuthenticated, 'showLogin:', showLogin); // Only process admin parameter once if (hasProcessedAdminParam) return; @@ -52,7 +53,10 @@ const AuthInitializer: React.FC = ({ children }) => { return ( setShowLogin(false)} + onComplete={() => { + console.log('onComplete called, setting showLogin to false'); + setShowLogin(false); + }} /> ); } diff --git a/src/components/Auth/LoginPrompt.tsx b/src/components/Auth/LoginPrompt.tsx index 0081703..5eafeef 100644 --- a/src/components/Auth/LoginPrompt.tsx +++ b/src/components/Auth/LoginPrompt.tsx @@ -1,6 +1,10 @@ import { useState } from 'react'; +import { IonIcon } from '@ionic/react'; +import { micOutline } from 'ionicons/icons'; import { useAppDispatch } from '../../redux/hooks'; import { setAuth } from '../../redux/authSlice'; +import { database } from '../../firebase/config'; +import { ref, get } from 'firebase/database'; import type { Authentication } from '../../types'; interface LoginPromptProps { @@ -9,77 +13,242 @@ interface LoginPromptProps { } const LoginPrompt: React.FC = ({ isAdmin, onComplete }) => { - const [singerName, setSingerName] = useState(isAdmin ? 'Admin' : ''); - const [partyId, setPartyId] = useState(''); + const [singerName, setSingerName] = useState(isAdmin ? 'Admin' : 'Matt'); + const [partyId, setPartyId] = useState('mbrucedogs-test'); const [error, setError] = useState(''); const dispatch = useAppDispatch(); - const handleSubmit = (e: React.FormEvent) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); + console.log('Login form submitted'); if (!partyId.trim() || !singerName.trim()) { setError('Please enter both Party Id and your name.'); return; } setError(''); - const auth: Authentication = { - authenticated: true, - singer: singerName.trim(), - isAdmin: isAdmin, - controller: partyId.trim(), - }; - dispatch(setAuth(auth)); - onComplete(); + + // Check if controller exists in Firebase + try { + const controllerRef = ref(database, `controllers/${partyId.trim()}`); + const snapshot = await get(controllerRef); + + if (!snapshot.exists()) { + setError('Invalid Party Id. Please check your Party Id and try again.'); + return; + } + + const auth: Authentication = { + authenticated: true, + singer: singerName.trim(), + isAdmin: isAdmin, + controller: partyId.trim(), + }; + console.log('Dispatching auth:', auth); + dispatch(setAuth(auth)); + console.log('Calling onComplete'); + onComplete(); + } catch (error) { + console.error('Error checking controller:', error); + setError('Error connecting to server. Please try again.'); + } }; return ( -
-
-
-

- Welcome to Karaoke! 🎤 -

-

- {isAdmin ? 'You have admin privileges' : 'Enter your Party Id and name to get started'} -

+ <> +
+
+
+

Login

+
+
+ +
+

Sings-A-Lot

+
+
+ +
+
+ + setPartyId(e.target.value)} + className="form-input" + autoFocus + /> +
+ +
+ + setSingerName(e.target.value)} + className="form-input" + /> +
+ + {error &&
{error}
} + + +
-
-
- - setPartyId(e.target.value)} - placeholder="Enter your Party Id" - className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" - autoFocus - /> -
-
- - setSingerName(e.target.value)} - placeholder={isAdmin ? 'Admin' : 'Enter your name'} - className="w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500" - /> -
- {error &&
{error}
} - -
-
+ + + ); };