import { useState, useEffect } from 'react'; import { motion } from 'framer-motion'; import { useAuth } from '@/context/AuthContext'; import { LogoIcon } from './Icons'; export function Login() { const { login } = useAuth(); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); // Debug: Log error state changes useEffect(() => { if (error) { console.log('Error state updated:', error); } }, [error]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); setLoading(true); try { await login({ username, password }); } catch (err) { // Extract error message from the error let errorMessage = 'Login failed. Please check your credentials.'; if (err instanceof Error) { errorMessage = err.message || errorMessage; } else if (typeof err === 'string') { errorMessage = err; } console.error('Login error:', err); console.log('Setting error message:', errorMessage); setError(errorMessage); } finally { setLoading(false); } }; return (
{/* Logo and Title */}

Video AdGenesis

Studio

Please sign in to continue

{/* Login Form */}
{/* Username Field */}
{ setUsername(e.target.value); if (error) setError(null); }} required className="w-full px-4 py-3 bg-void-900/50 border border-void-700 rounded-lg text-void-100 placeholder-void-500 focus:outline-none focus:ring-2 focus:ring-coral-500 focus:border-transparent transition-all" placeholder="Enter your username" autoComplete="username" />
{/* Password Field */}
{ setPassword(e.target.value); if (error) setError(null); }} required className="w-full px-4 py-3 bg-void-900/50 border border-void-700 rounded-lg text-void-100 placeholder-void-500 focus:outline-none focus:ring-2 focus:ring-coral-500 focus:border-transparent transition-all" placeholder="Enter your password" autoComplete="current-password" />
{/* Error Message */} {error ? ( {error} ) : null} {/* Submit Button */}
{/* Footer */}

Restricted access - Authorized users only

); }