Files
impuestospy/apps/web/app/[locale]/(auth)/registro/register-form.tsx
T
MichilisandClaude Opus 5 0d7651b17c phase-2: identity, from the landing hook to the profile screen
Flows A1 to A6 and E3 end to end. A visitor types a RUC on the landing page,
sees their real filing dates, registers, verifies a six digit code, grants
consent, completes a three step setup and lands on the first run screen, with
the profile, consent and audit rows to show for it.

API: public RUC lookup behind a token bucket (10/min/IP), the full /me surface
(profile, dependents, consents, notification prefs, data export, account
deletion), an append-only audit module that exports an insert and nothing else,
and a PII module that is the only thing allowed near those tables.

Deletion and consent revocation both freeze the account and drop every session,
reusing better-auth's ban flag rather than adding a second notion of disabled.
Nothing is destroyed yet: the purge is a job for phase 4. deadlineDigit is
always derived server side, never accepted from the client.

Web: landing with the RUC hook, registration, OTP verification, consent, the
setup wizard, the profile screen with "Tus datos", and legal pages that ship as
marked placeholders per COPY.md section 13. Money, Skeleton, Switch and
EmptyState components added.

The seed is now complete for identity: Maria at 4123456-1, filing digit 6 and
day 19, with a dependant, consents and prefs; Carlos as an IVA-only company.

Two real defects found by building the screens and fixed with tests:
the OTP boxes dropped a digit because the handler fired effects inside a
setState updater that React 19 invokes twice, and the switch knob rendered
outside its track because translate-x-5.5 does not resolve.

232 vitest tests, 26 Playwright tests across mobile and desktop, coverage still
100% on the rules, typecheck and lint clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-03 23:33:10 +00:00

103 lines
3.4 KiB
TypeScript

'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 (
<Card className="space-y-6">
<h1 className="text-2xl font-semibold tracking-tight text-balance">
{t('auth.register.title')}
</h1>
<form
className="space-y-4"
onSubmit={(event) => {
event.preventDefault();
const data = new FormData(event.currentTarget);
register.mutate({
email: String(data.get('email') ?? '').trim(),
password: String(data.get('password') ?? ''),
});
}}
>
<div className="space-y-1.5">
<Label htmlFor="email">{t('auth.register.email')}</Label>
<Input
id="email"
name="email"
type="email"
autoComplete="email"
required
aria-invalid={register.isError}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="password">{t('auth.register.password')}</Label>
<Input
id="password"
name="password"
type="password"
autoComplete="new-password"
minLength={8}
required
aria-describedby="password-hint"
aria-invalid={register.isError}
/>
<p id="password-hint" className="text-sm text-[var(--text-muted)]">
{t('auth.register.passwordHint')}
</p>
</div>
{register.isError ? (
<p role="alert" className="text-sm text-overdue">
{emailTaken ? t('auth.register.emailTaken') : t('auth.register.failed')}
</p>
) : null}
<Button type="submit" size="lg" block disabled={register.isPending}>
{register.isPending ? t('common.loading') : t('auth.register.submit')}
</Button>
</form>
<p className="text-sm text-[var(--text-muted)]">
{t('auth.register.haveAccount')}{' '}
<Link href="/login" className="font-medium text-accent-700 hover:underline">
{t('auth.register.signIn')}
</Link>
</p>
</Card>
);
}