import { useState } from 'react'; import { Link, useNavigate } from 'react-router'; import { Shield } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; import { useAuthStore } from '@/stores/auth'; import { ApiError } from '@/lib/api'; export function RegisterPage() { const navigate = useNavigate(); const register = useAuthStore((s) => s.register); const [email, setEmail] = useState(''); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { await register(email, username, password); navigate('/'); } catch (err) { if (err instanceof ApiError) { setError(err.status === 409 ? 'Email or username already taken' : 'An error occurred'); } else { setError('An error occurred'); } } finally { setLoading(false); } }; return (
Create an account Get started with GamePanel
{error && (
{error}
)}
setEmail(e.target.value)} required />
setUsername(e.target.value)} required />
setPassword(e.target.value)} required minLength={8} />

Already have an account?{' '} Sign in

); }