import { useState, useEffect } from 'react'; import { auth } from '../utils/api'; import ErrorMessage from './ErrorMessage'; export default function Login() { const [providers, setProviders] = useState({ google: false, discord: false, local: false, }); const [showRegister, setShowRegister] = useState(false); const [email, setEmail] = useState(''); const [name, setName] = useState(''); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); useEffect(() => { checkAuthProviders(); // Check for registration disabled error in URL const urlParams = new URLSearchParams(window.location.search); if (urlParams.get('error') === 'registration_disabled') { setError('Registration is currently disabled. Please contact an administrator.'); } }, []); const checkAuthProviders = async () => { try { const result = await auth.getProviders(); setProviders({ google: result.google || false, discord: result.discord || false, local: result.local || false, }); } catch (error) { // If endpoint fails, assume no providers are available console.error('Failed to check auth providers:', error); setProviders({ google: false, discord: false, local: false }); } }; const handleLocalLogin = async (e) => { e.preventDefault(); setError(''); setLoading(true); try { await auth.localLogin(username, password); // Reload page to trigger auth check in App component window.location.reload(); } catch (err) { setError(err.message || 'Login failed'); setLoading(false); } }; const handleLocalRegister = async (e) => { e.preventDefault(); setError(''); if (password !== confirmPassword) { setError('Passwords do not match'); return; } if (password.length < 8) { setError('Password must be at least 8 characters long'); return; } setLoading(true); try { await auth.localRegister(email, name, password); // Reload page to trigger auth check in App component window.location.reload(); } catch (err) { setError(err.message || 'Registration failed'); setLoading(false); } }; return (

JiggaBlend

Blender Render Farm

{providers.local && (
{!showRegister ? (
setUsername(e.target.value)} required className="w-full px-4 py-2 bg-gray-900 border border-gray-600 rounded-lg text-gray-100 focus:ring-2 focus:ring-orange-500 focus:border-transparent placeholder-gray-500" placeholder="Enter your email" />
setPassword(e.target.value)} required className="w-full px-4 py-2 bg-gray-900 border border-gray-600 rounded-lg text-gray-100 focus:ring-2 focus:ring-orange-500 focus:border-transparent placeholder-gray-500" placeholder="Enter password" />
) : (
setEmail(e.target.value)} required className="w-full px-4 py-2 bg-gray-900 border border-gray-600 rounded-lg text-gray-100 focus:ring-2 focus:ring-orange-500 focus:border-transparent placeholder-gray-500" placeholder="Enter your email" />
setName(e.target.value)} required className="w-full px-4 py-2 bg-gray-900 border border-gray-600 rounded-lg text-gray-100 focus:ring-2 focus:ring-orange-500 focus:border-transparent placeholder-gray-500" placeholder="Enter your name" />
setPassword(e.target.value)} required minLength={8} className="w-full px-4 py-2 bg-gray-900 border border-gray-600 rounded-lg text-gray-100 focus:ring-2 focus:ring-orange-500 focus:border-transparent placeholder-gray-500" placeholder="At least 8 characters" />
setConfirmPassword(e.target.value)} required minLength={8} className="w-full px-4 py-2 bg-gray-900 border border-gray-600 rounded-lg text-gray-100 focus:ring-2 focus:ring-orange-500 focus:border-transparent placeholder-gray-500" placeholder="Confirm password" />
)}
)} {providers.google && ( Continue with Google )} {providers.discord && ( Continue with Discord )} {!providers.google && !providers.discord && !providers.local && (
No authentication methods are configured. Please contact an administrator.
)}
); }