Cadastro
Carregando a demo interativa…
A demo acima roda o SDK de verdade (createEnginexClient) com fetch: createMockFetch(...) de @getenginex/sdk/testing: nenhuma chamada sai para a rede. Troque o cenário para ver cpf_already_registered e captcha_required. O painel Under the hood mostra a chamada feita (senhas e tokens mascarados), os requests vistos pelos hooks, o resultado ou o EnginexError e a sessão. O código abaixo é o equivalente para o seu app.
Fluxo completo, com consulta de CPF e verificação:
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 })Reenvios: enginex.auth.resendVerificationEmail({ userId }) e enginex.auth.resendPhoneVerification({ userId }).