> ## 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.

# Log in with email OTP codes

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

<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
  (cloud is platform-capped at 60s; CLI supports up to 10 minutes).
</Tip>

## Related

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