"use client" import { useState } from "react" import { signIn } from "next-auth/react" import { useRouter } from "next/navigation" import Link from "next/link" export default function SignupPage() { const [step, setStep] = useState<"form" | "loading">("form") const [charityName, setCharityName] = useState("") const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [error, setError] = useState("") const router = useRouter() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!charityName.trim() || !email.trim() || !password) return setError("") setStep("loading") try { const res = await fetch("/api/auth/signup", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password, charityName, name: "" }), }) const data = await res.json() if (!res.ok) { setError(data.error || "Something went wrong") setStep("form") return } // Auto sign in and go straight to dashboard const result = await signIn("credentials", { email, password, redirect: false }) if (result?.error) { setError("Account created — please sign in") setStep("form") } else { router.push("/dashboard") } } catch { setError("Connection error. Try again.") setStep("form") } } if (step === "loading") { return (
Setting up your charity...
Free. 30 seconds. No card.
Already have an account? Sign in