"use client"; import { useState } from "react"; import { signIn, signUp } from "@farm.js/auth/client"; interface AuthFormProps { mode: "sign-in" | "sign-up"; } export function AuthForm({ mode }: AuthFormProps) { const isSignUp = mode === "sign-up"; const [pending, setPending] = useState(false); const [error, setError] = useState(null); async function submit(event: React.FormEvent) { event.preventDefault(); setError(null); setPending(true); const formData = new FormData(event.currentTarget); const email = String(formData.get("email") ?? "").trim(); const password = String(formData.get("password") ?? ""); const name = String(formData.get("name") ?? "").trim(); try { const response = isSignUp ? await signUp({ email, name, password, }) : await signIn({ email, password, }); if (response.error) { setError(response.error.message ?? "We could not complete that request."); setPending(false); return; } window.location.assign("/dashboard"); } catch { setError("The authentication service could not be reached. Please try again."); setPending(false); } } return (
{isSignUp ? "01 / SIGN UP" : "01 / SIGN IN"}

{isSignUp ? "Create account." : "Welcome back."}

{isSignUp ? ( ) : null} {error ? (
Authentication failed {error}
) : null}

{isSignUp ? "Have an account?" : "Need an account?"}{" "} {isSignUp ? "Sign in →" : "Sign up →"}

); }