Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/dev0302/nextjs-project-1/llms.txt

Use this file to discover all available pages before exploring further.

This endpoint begins the registration flow by generating a unique 6-digit numeric OTP and delivering it to the provided email address via the Brevo transactional email API. The OTP is stored in MongoDB with a 5-minute TTL and must be submitted alongside the other registration fields to the POST /api/sign-up endpoint to complete account creation.

Method and URL

POST /api/send-otp

Authentication

None required. This endpoint is publicly accessible.

Request Body

email
string
required
The email address to send the OTP to. Must be a valid email address that has not already been registered.

Example Request

{
  "email": "alex@example.com"
}

Responses

200 — OTP Sent Successfully

The OTP was generated and dispatched to the provided email address. The user should check their inbox and submit the OTP to POST /api/sign-up within 5 minutes.
{
  "success": true,
  "message": "OTP sent successfully"
}

409 — User Already Registered

An account with this email address already exists in the database. Sign in instead.
{
  "success": false,
  "message": "User already registered"
}

500 — Internal Server Error

The OTP could not be generated or sent. This may be caused by a database connection failure or a Brevo API error.
{
  "success": false,
  "message": "Failed to send OTP"
}

curl Example

curl --request POST \
  --url https://your-domain.com/api/send-otp \
  --header 'Content-Type: application/json' \
  --data '{
    "email": "alex@example.com"
  }'

Notes

The OTP is generated using the otp-generator library with upperCaseAlphabets, lowerCaseAlphabets, and specialChars all set to false. The result is always a 6-digit numeric string (e.g., "482910").
Uniqueness of each OTP is enforced at the database level by a MongoDB unique index on the otp field of the OTP collection. If a collision is detected (error code 11000), the server automatically retries the generation loop until a unique OTP is produced before sending.
The OTP document carries a 5-minute TTL enforced by MongoDB. Submitting an expired OTP to POST /api/sign-up will result in an Invalid OTP error. Request a new OTP if the window has passed.

Build docs developers (and LLMs) love