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

# Verify an OTP Code with Node.js

> Verify the OTP code a user typed from Node.js with the Hypersender OTP API. Handle wrong, used, and expired codes for WhatsApp and SMS OTP verification flows.

Check whether an OTP code is correct, unexpired, and unused using the Node SDK. Use this after the user submits the code they received via WhatsApp.

## Parameters

| Field | Type | Required | Description |
| - | - | - | - |
| chatId | string | yes | The chat ID or, for SMS, the phone number that received the code. |
| code | string | yes | The OTP code entered by the user. |

## Validate the code

```typescript theme={null}
import { Hypersender } from "hypersender-node";
import { HypersenderError } from "hypersender-node/models/errors";

try {
  const result = await Hypersender.otp().validateCode({
    chatId: "+201001234567",
    code: "439713",
  });

  if (result.data?.status === "validated") {
    // proceed with login or protected action
  }
} catch (error) {
  if (!(error instanceof HypersenderError)) throw error;
  // Validation failed (error.statusCode is 422); do not treat the user as verified
}
```

The method returns the parsed response on success and throws an error that extends `HypersenderError` on any `4XX` or `5XX` response.

### Common failure reasons

* Code does not match the active OTP
* Code expired based on `expires` value
* Code already used (single-use)
* No active OTP found for the `chatId`

> [!WARNING]
>
> Implement rate limits on validation attempts (e.g., max 3-5 tries) to block brute-force guessing.

## Next

For passwordless login flows, try [Generate OTP Link](https://docs.hypersender.com/v2/packages-and-sdks/node/otp/generate-whatsapp-otp-link-with-node.md) to avoid manual code entry.


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