"use client"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { RefreshCw, UserPlus } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { api } from "@/lib/api-client"; export default function RegisterPage() { const router = useRouter(); const [name, setName] = useState(""); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [captcha, setCaptcha] = useState(""); const [challenge, setChallenge] = useState(""); const [submitting, setSubmitting] = useState(false); const loadCaptcha = async () => { const { challenge } = await api.captcha(); setChallenge(challenge); setCaptcha(""); }; useEffect(() => { api.captcha() .then(({ challenge }) => setChallenge(challenge)) .catch(() => toast.error("Unable to load captcha")); }, []); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); setSubmitting(true); try { await api.register(name, username, password, captcha); toast.success("Account created"); router.push("/snippets"); router.refresh(); } catch (error) { toast.error(error instanceof Error ? error.message : "Unable to create account"); await loadCaptcha(); } finally { setSubmitting(false); } }; return (

Create account

Create a fully local account for CVault.

setName(event.target.value)} className="h-11 bg-muted/50 border-border/50" required />
setUsername(event.target.value)} className="h-11 bg-muted/50 border-border/50" required />
setPassword(event.target.value)} className="h-11 bg-muted/50 border-border/50" minLength={8} required />
setCaptcha(event.target.value)} className="h-11 bg-muted/50 border-border/50" required />

Already have an account?{" "} Sign in

); }