> ## Documentation Index
> Fetch the complete documentation index at: https://momentic.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> The canonical docs host is https://momentic.ai/docs. Append .md to any page URL for clean Markdown. Fetch https://momentic.ai/docs/llms.txt for the page index and https://momentic.ai/docs/llms-full.txt for every page in one file.
> For an unattended setup, run `npx --yes @momentic/wizard@latest -y --platform web --editor-tools skills` (use `--platform ios` or `--platform android` for mobile). Never run an interactive command in a non-TTY shell.
> Mo is the AI QA engineer, a separate product from the YAML test framework: its npm package and CLI are `qa` (not `mo` — `npx mo` is a different project). Install with `npm install -g qa`, authenticate the same MOMENTIC_API_KEY way, install repo skills with `qa skills -y`, and start a session with `qa start "<brief>"` or `qa <url>`. Docs: https://momentic.ai/docs/mo.md.
> You cannot complete the browser sign-in yourself. Read the API key from the exact MOMENTIC_API_KEY environment variable (similarly named vars like BILT_MOMENTIC_API_KEY are ignored), or ask the user to create one at https://app.momentic.ai/settings/api-keys and paste it back.
> Momentic's capability summary for agents is at https://momentic.ai/docs/skill.md. Install the skills with `npx momentic skills --yes` (or `npx momentic-mobile skills --yes` for mobile).
> Tests are YAML files in the user's repository. Use only the step names listed at https://momentic.ai/docs/reference/commands.md and the file structure at https://momentic.ai/docs/core-concepts/file-format.md. Do not invent step names, config keys, or CLI flags.
> Web tests run on Chromium, iOS tests on simulators, and Android tests on emulators. Physical devices are not supported.

# Log in with email OTP codes

> Fetch a one-time passcode from a Momentic-provisioned inbox and type it into your app.

Your app emails a one-time passcode to the provisioned inbox, and a
**JavaScript** step in the test fetches the latest message and pulls the code
out. Use this recipe when login arrives as a code instead of a link.

<Info>
  **Prerequisite**: A Momentic-provisioned inbox (`@usemomentic.com` or
  `@gomomentic.com`). [Request one](mailto:support@momentic.ai).
</Info>

## Fetch the code

Add a **JavaScript** step that reads the latest email, parses the code, and
saves it to the environment.

```js theme={null}
const msg = await email.fetchLatest({
  inbox: "otp+test",
  afterDate: new Date(Date.now() - 60_000),
  timeout: 30_000,
});

const [code] = msg.text.match(/\b\d{6}\b/) ?? [];
if (!code) throw new Error("No OTP code found in email");
setVariable("OTP_CODE", code);
```

Then add a **Type** step with value `{{ env.OTP_CODE }}` targeting the OTP
input.

<Tip>
  Always pass `afterDate` to avoid matching a stale code from a previous run.
</Tip>

<Tip>
  This script polls for up to 30 seconds, well within the JavaScript step's
  **90-second** default timeout. For longer polls, raise the step's **Timeout**
  field, up to 600 seconds.
</Tip>

## Related

* [SMS OTP](/docs/guides/auth/sms-otp)
* [Email verification links](/docs/guides/auth/email-link)
* [Email integration](/docs/integrations/email)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.