"use client" import { FormInput } from "@/components/forms/simple" import { Button } from "@/components/ui/button" import { authClient } from "@/lib/auth-client" import { useRouter } from "next/navigation" import { useState } from "react" export default function SignupForm() { const [name, setName] = useState("") const [email, setEmail] = useState("") const [otp, setOtp] = useState("") const [isOtpSent, setIsOtpSent] = useState(false) const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const router = useRouter() const handleSendOtp = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError(null) try { await authClient.emailOtp.sendVerificationOtp({ email, type: "sign-in", }) setIsOtpSent(true) } catch (err) { setError(err instanceof Error ? err.message : "Failed to send OTP") } finally { setIsLoading(false) } } const handleVerifyOtp = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError(null) try { await authClient.signIn.emailOtp({ email, otp, }) await authClient.updateUser({ name, }) router.push("/dashboard") } catch (err) { setError(err instanceof Error ? err.message : "Failed to verify OTP") } finally { setIsLoading(false) } } return (
setName(e.target.value)} required disabled={isOtpSent} /> setEmail(e.target.value)} required disabled={isOtpSent} /> {isOtpSent && ( setOtp(e.target.value)} required maxLength={6} pattern="[0-9]{6}" /> )} {error &&

{error}

} ) }