import React, { useState } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { supabase, isSupabaseConfigured } from '../../lib/supabaseClient'; import { Button } from '../../components/Button'; import { useAuth } from '../../context/AuthContext'; import { UserPlus, AlertCircle, ArrowLeft, CheckCircle, Mail, Info, Send, ShieldCheck } from 'lucide-react'; export const Register: React.FC = () => { const navigate = useNavigate(); const { refreshDemoUser } = useAuth(); const [lastName, setLastName] = useState(''); const [firstName, setFirstName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [dateOfBirth, setDateOfBirth] = useState(''); const [privacyAccepted, setPrivacyAccepted] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const handleRegister = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(null); // Alapvető validációk if (!lastName || !firstName) { setError('A név megadása kötelező.'); setLoading(false); return; } if (password !== confirmPassword) { setError('A jelszavak nem egyeznek.'); setLoading(false); return; } if (password.length < 6) { setError('A jelszónak legalább 6 karakter hosszúnak kell lennie.'); setLoading(false); return; } if (!dateOfBirth) { setError('A születési dátum megadása kötelező.'); setLoading(false); return; } if (!privacyAccepted) { setError('A regisztrációhoz el kell fogadnia az Adatkezelési tájékoztatót.'); setLoading(false); return; } try { if (!isSupabaseConfigured) { // Demo mód szimuláció await new Promise(resolve => setTimeout(resolve, 1000)); const demoUser = { user: { id: 'demo-user-123', email: email, user_metadata: { first_name: firstName, last_name: lastName, date_of_birth: dateOfBirth } }, access_token: 'demo-token', }; localStorage.setItem('demo_user_session', JSON.stringify(demoUser)); refreshDemoUser(); navigate('/dashboard'); return; } // HashRouter esetén a redirect URL-nek pontosnak kell lennie. // A window.location.origin a base URL (pl. http://localhost:5173) const redirectUrl = `${window.location.origin}/#/auth/login`; console.log('Attempting signup with redirect:', redirectUrl); const { data, error: signUpError } = await supabase.auth.signUp({ email, password, options: { emailRedirectTo: redirectUrl, data: { first_name: firstName, last_name: lastName, date_of_birth: dateOfBirth, } } }); if (signUpError) { console.error('Detailed registration error:', signUpError); // Specifikus hibaüzenetek kezelése if (signUpError.message.includes('Error sending confirmation email')) { setError('A rendszer nem tudta kiküldeni a megerősítő e-mailt a Resend szerverén keresztül. Kérjük, ellenőrizze, hogy a Supabase Dashboard-on a "Custom SMTP" beállításoknál a Sender Email megegyezik-e a Resend-ben hitelesített domainnel!'); } else if (signUpError.message.includes('User already registered') || signUpError.status === 422) { setError('Ezzel az e-mail címmel már regisztráltak. Kérjük, próbáljon meg bejelentkezni.'); } else if (signUpError.status === 429) { setError('Túl sok regisztrációs kísérlet. Kérjük, várjon néhány percet!'); } else { setError(`Hiba történt a regisztráció során: ${signUpError.message}`); } setLoading(false); return; } if (data.user) { // Ha azonnal van session, akkor nincs e-mail megerősítés (ritka egyedi SMTP-nél) if (data.session) { navigate('/dashboard'); } else { setSuccess(true); } } } catch (err: any) { setError('Váratlan hiba történt a regisztráció során. Kérjük, próbálja meg később.'); console.error('Unexpected catch error:', err); } finally { setLoading(false); } }; if (success) { return (

E-mail kiküldve!

Küldtünk egy megerősítő linket a(z) {email} e-mail címre a Resend szolgáltatón keresztül. A belépéshez kérjük, kattintson a levélben található linkre.

Nem találja a levelet?

Nézze meg a Spam vagy a Promóciók mappát is. Ha 5 percen belül nem érkezik meg, próbálja meg újra a bejelentkezési oldalon az újraküldést.

); } return (

Regisztráció

Csatlakozzon a MotionWeb közösségéhez.

{error && (
{error}
)}
setLastName(e.target.value)} className="appearance-none block w-full px-4 py-3 border border-gray-200 rounded-xl shadow-sm focus:outline-none focus:ring-4 focus:ring-primary/10 focus:border-primary sm:text-sm bg-white text-gray-900 font-medium" placeholder="Kovács" />
setFirstName(e.target.value)} className="appearance-none block w-full px-4 py-3 border border-gray-200 rounded-xl shadow-sm focus:outline-none focus:ring-4 focus:ring-primary/10 focus:border-primary sm:text-sm bg-white text-gray-900 font-medium" placeholder="János" />
setEmail(e.target.value)} className="appearance-none block w-full px-4 py-3 border border-gray-200 rounded-xl shadow-sm focus:outline-none focus:ring-4 focus:ring-primary/10 focus:border-primary sm:text-sm bg-white text-gray-900 font-medium" placeholder="pelda@email.hu" />
setDateOfBirth(e.target.value)} className="appearance-none block w-full px-4 py-3 border border-gray-200 rounded-xl shadow-sm focus:outline-none focus:ring-4 focus:ring-primary/10 focus:border-primary sm:text-sm bg-white text-gray-900 font-medium" />
setPassword(e.target.value)} className="appearance-none block w-full px-4 py-3 border border-gray-200 rounded-xl shadow-sm focus:outline-none focus:ring-4 focus:ring-primary/10 focus:border-primary sm:text-sm bg-white text-gray-900 font-medium" placeholder="••••••••" />
setConfirmPassword(e.target.value)} className="appearance-none block w-full px-4 py-3 border border-gray-200 rounded-xl shadow-sm focus:outline-none focus:ring-4 focus:ring-primary/10 focus:border-primary sm:text-sm bg-white text-gray-900 font-medium" placeholder="••••••••" />
setPrivacyAccepted(e.target.checked)} className="h-5 w-5 text-primary focus:ring-primary border-gray-300 rounded-lg cursor-pointer mt-0.5" />
Már van fiókja? Jelentkezzen be
Vissza a főoldalra
); };