Registro
Cargando la demo interactiva…
La demo de arriba ejecuta el SDK real (createEnginexClient) con fetch: createMockFetch(...) de @getenginex/sdk/testing: ninguna llamada sale a la red. Cambia el escenario para ver cpf_already_registered y captcha_required. El panel Under the hood muestra la llamada realizada (contraseñas y tokens enmascarados), los requests vistos por los hooks, el resultado o el EnginexError y la sesión. El código de abajo es el equivalente para tu app.
Flujo completo, con consulta de CPF y verificación:
ts
import { isEnginexError } from '@getenginex/sdk'
// 1. (optional) prefill with data from the tax authority
try {
const cpfData = await enginex.auth.lookupCpf({ cpf: form.cpf })
form.name = cpfData.name
form.birthDate = cpfData.birthDate
} catch (e) {
if (isEnginexError(e, 'captcha_required')) {
const siteKey = e.details?.site_key // string | undefined
// render the captcha and retry with { cpf, captchaToken }
} else if (isEnginexError(e, 'cpf_already_registered')) {
// offer login or password recovery
} else throw e
}
// 2. record progress (non-blocking)
void enginex.auth.saveLead({ cpf: form.cpf, stepCompleted: 'cpf' })
// 3. create the account. The captcha is required when config.captcha.enabled
const config = await enginex.config.get()
const { userId } = await enginex.auth.register({
email: form.email,
password: form.password,
cpf: form.cpf,
name: form.name,
birthDate: form.birthDate,
phone: form.phone,
referralCode: form.referralCode, // optional: referral code
captchaToken: config.captcha.enabled ? await getCaptchaToken(config.captcha.siteKey) : undefined,
})
// 4. verify email and phone
await enginex.auth.verifyEmail({ userId, code: emailCode })
await enginex.auth.verifyPhone({ userId, otp: smsCode })
// 5. log in
await enginex.auth.login({ email: form.email, password: form.password })Reenvíos: enginex.auth.resendVerificationEmail({ userId }) y enginex.auth.resendPhoneVerification({ userId }).