import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { useAuth } from '../hooks/useAuth' import './Login.css' function Register() { const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const { register } = useAuth() const navigate = useNavigate() const validateEmail = (email: string) => { const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ return re.test(email) } const getPasswordStrength = (password: string): { strength: string; color: string } => { if (password.length === 0) return { strength: '', color: '' } if (password.length < 6) return { strength: 'Weak', color: '#ff6b6b' } if (password.length < 10) return { strength: 'Medium', color: '#ffd93d' } return { strength: 'Strong', color: '#51cf66' } } const passwordStrength = getPasswordStrength(password) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') // Validation if (!validateEmail(email)) { setError('Please enter a valid email address') return } if (password.length < 6) { setError('Password must be at least 6 characters') return } if (password !== confirmPassword) { setError('Passwords do not match') return } setLoading(true) try { await register(email, password) // Navigate to character selection after successful registration navigate('/characters') } catch (err: any) { setError(err.response?.data?.detail || 'Registration failed') } finally { setLoading(false) } } return (
Join the survivors in the wasteland