"use client" import { useState } from "react" import { signIn } from "next-auth/react" import Link from "next/link" import { Loader2 } from "lucide-react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" /** * Signup form for an invited user. * * The invite token is deliberately absent: it lives in an HttpOnly cookie set by * /invite/, and the register route reads it server-side. Nothing here can * see or forge it. */ export function JoinForm() { const [name, setName] = useState("") const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [confirmPassword, setConfirmPassword] = useState("") const [error, setError] = useState("") const [loading, setLoading] = useState(false) async function handleSubmit(e: React.FormEvent) { e.preventDefault() setError("") if (password !== confirmPassword) { setError("Passwords do not match") return } if (password.length < 10) { setError("Password must be at least 10 characters") return } if (!/[a-z]/.test(password) || !/[A-Z]/.test(password) || !/[0-9]/.test(password)) { setError("Password must contain lowercase, uppercase, and a number") return } setLoading(true) try { const res = await fetch("/api/auth/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name, email, password }), }) const data = await res.json() if (!res.ok) { setError(data.error || "Registration failed") setLoading(false) return } await signIn("credentials", { email, password, callbackUrl: "/dashboard" }) } catch { setError("Something went wrong. Please try again.") setLoading(false) } } return ( <>
{error && (
{error}
)}
setName(e.target.value)} required maxLength={100} disabled={loading} />
setEmail(e.target.value)} required disabled={loading} />
setPassword(e.target.value)} required minLength={10} maxLength={128} disabled={loading} />
setConfirmPassword(e.target.value)} required minLength={10} disabled={loading} />

Already have an account?{" "} Sign in

) }