"use client"; import { useState } from "react"; import Link from "next/link"; import { createUserWithEmailAndPassword, GoogleAuthProvider, signInWithPopup } from "firebase/auth"; import { auth } from "@/lib/firebase"; import { useRouter } from "next/navigation"; /** * Self-serve account creation (SAAS_PLAN.md B4). Only creates the Firebase * user — org naming happens on the next screen, /onboarding, which is also * where every other no-org-yet path (Google sign-in via /login, etc.) ends * up. Keeping that step in one shared place means there's exactly one route * that calls POST /auth/signup. */ export default function SignupPage() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const router = useRouter(); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(null); try { await createUserWithEmailAndPassword(auth, email, password); router.push("/onboarding"); } catch (err: unknown) { const code = (err as { code?: string })?.code; if (code === "auth/email-already-in-use") { setError("An account with this email already exists. Try signing in instead."); } else if (code === "auth/weak-password") { setError("Password is too weak — use at least 6 characters."); } else { setError("Could not create your account. Check your details and try again."); } } finally { setLoading(false); } } async function handleGoogle() { setLoading(true); setError(null); try { await signInWithPopup(auth, new GoogleAuthProvider()); router.push("/onboarding"); } catch { setError("Google sign-up failed. Try again."); } finally { setLoading(false); } } return (
D DRB

Create your account

setEmail(e.target.value)} required autoComplete="email" className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500" />
setPassword(e.target.value)} required minLength={6} autoComplete="new-password" className="w-full bg-gray-800 border border-gray-700 rounded-lg px-3 py-2 text-white text-sm focus:outline-none focus:border-indigo-500" />
{error &&

{error}

}
or

Already have an account?{" "} Sign in

); }