"use client"; import { AnimatePresence, motion } from "motion/react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { signIn, signUp } from "@/lib/auth/client"; const fieldVariants = { hidden: { opacity: 0, y: 10 }, visible: { opacity: 1, y: 0, transition: { type: "spring" as const, stiffness: 300, damping: 24 }, }, }; export function AuthForm({ mode }: { mode: "login" | "register" }) { const router = useRouter(); const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const isRegister = mode === "register"; async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(""); setLoading(true); try { if (isRegister) { const result = await signUp.email({ name, email, password }); if (result.error) { setError(result.error.message ?? "Registration failed"); return; } } else { const result = await signIn.email({ email, password }); if (result.error) { setError(result.error.message ?? "Login failed"); return; } } router.push("/dashboard"); router.refresh(); } catch { setError("Something went wrong"); } finally { setLoading(false); } } return (
{/* Subtle glow behind card */}
Couch Potato

{isRegister ? "Create your account" : "Welcome back"}

{isRegister ? "Start tracking your watches" : "Sign in to continue"}

{isRegister && ( setName(e.target.value)} className="flex h-11 w-full rounded-lg border border-border/50 bg-background/50 px-4 text-sm transition-colors placeholder:text-muted-foreground/50 focus:border-primary/40 focus:outline-none focus:ring-1 focus:ring-primary/20" placeholder="Your name" /> )} setEmail(e.target.value)} className="flex h-11 w-full rounded-lg border border-border/50 bg-background/50 px-4 text-sm transition-colors placeholder:text-muted-foreground/50 focus:border-primary/40 focus:outline-none focus:ring-1 focus:ring-primary/20" placeholder="you@example.com" /> setPassword(e.target.value)} className="flex h-11 w-full rounded-lg border border-border/50 bg-background/50 px-4 text-sm transition-colors placeholder:text-muted-foreground/50 focus:border-primary/40 focus:outline-none focus:ring-1 focus:ring-primary/20" placeholder="Min 8 characters" /> {error && ( {error} )} {loading ? "Loading..." : isRegister ? "Create account" : "Sign in"}

{isRegister ? ( <> Already have an account?{" "} Sign in ) : ( <> Don't have an account?{" "} Register )}

); }