'use client'; import { useMutation } from '@tanstack/react-query'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Link, useRouter } from '@/i18n/navigation'; import { useT } from '@/i18n/t'; import { authClient } from '@/lib/auth-client'; /** * Flow A3. One screen, no marketing interruptions: email, password, and straight on to * the six digit code. */ export function RegisterForm() { const t = useT(); const router = useRouter(); const [emailTaken, setEmailTaken] = useState(false); const register = useMutation({ mutationFn: async (form: { email: string; password: string }) => { setEmailTaken(false); const { error } = await authClient.signUp.email({ ...form, name: form.email }); if (error) { // better-auth reports an existing account with 422 USER_ALREADY_EXISTS. if (error.status === 422 || error.code === 'USER_ALREADY_EXISTS') setEmailTaken(true); throw new Error(error.code ?? 'sign_up_failed'); } await authClient.emailOtp.sendVerificationOtp({ email: form.email, type: 'email-verification' }); return form.email; }, onSuccess: (email) => router.push(`/verificar?email=${encodeURIComponent(email)}`), }); return (

{t('auth.register.title')}

{ event.preventDefault(); const data = new FormData(event.currentTarget); register.mutate({ email: String(data.get('email') ?? '').trim(), password: String(data.get('password') ?? ''), }); }} >

{t('auth.register.passwordHint')}

{register.isError ? (

{emailTaken ? t('auth.register.emailTaken') : t('auth.register.failed')}

) : null}

{t('auth.register.haveAccount')}{' '} {t('auth.register.signIn')}

); }