Skip to main content
Email OTP sends a short numeric code to the user’s inbox. It works well for mobile flows where clicking a link is awkward and for verification steps inside an existing session.

Setup

1

Install

2

Add the plugin

lib/kavach.ts

How it works

  1. User submits their email to POST /auth/email-otp/send.
  2. KavachOS generates a cryptographically random code and calls your onSendOtp function with the email and code.
  3. User enters the code in your UI and submits to POST /auth/email-otp/verify.
  4. On success, a session cookie is set.
If the email belongs to an existing account, the same user ID is returned. If it is new, an account is created automatically.

Send a code

POST /auth/email-otp/send
The response is always 200 to prevent email enumeration. Codes are rate-limited to one per minute per email address, requests within the window return 429. Build a countdown timer into your UI.

Verify a code

POST /auth/email-otp/verify
After maxAttempts failed verifications, the code is invalidated and a new one must be requested.
Codes are single-use. A successful verification invalidates the code immediately. Do not retry the same code after a success response.

Options

Last modified on April 29, 2026