import { useState, type FormEvent } from "react"; import { useNavigate, Link } from "react-router"; import { api } from "~/api/client"; import { Button } from "~/components/Button"; import { Input } from "~/components/Input"; export default function Register() { const navigate = useNavigate(); const [email, setEmail] = useState(""); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setError(""); if (password !== confirmPassword) { setError("Passwords do not match"); return; } if (password.length < 6) { setError("Password must be at least 6 characters"); return; } setLoading(true); try { await api.register({ email, username, password }); navigate("/dashboard"); } catch (err) { setError(err instanceof Error ? err.message : "Registration failed"); } finally { setLoading(false); } }; return (
Create your account
Already have an account?{" "} Sign in