---
url: https://game-engine-io.github.io/enginex-frontend-sdk/flows/sign-up.md
---
# Sign-up

The demo above runs the real SDK (`createEnginexClient`) with `fetch: createMockFetch(...)` from
[`@getenginex/sdk/testing`](/guide/testing): no call goes out to the network. Switch the scenario to
see `cpf_already_registered` and `captcha_required`. The **Under the hood** panel shows the call made
(passwords and tokens masked), the requests seen by the [hooks](/concepts/extensibility), the result or
the `EnginexError`, and the session. The code below is the equivalent for your app.

Full flow, with CPF lookup and verification:

```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 })
```

Resends: `enginex.auth.resendVerificationEmail({ userId })` and `enginex.auth.resendPhoneVerification({ userId })`.
