"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 (
{isRegister ? "Start tracking your watches" : "Sign in to continue"}
{isRegister ? ( <> Already have an account?{" "} Sign in > ) : ( <> Don't have an account?{" "} Register > )}