Skip to main content
The phoneAuth plugin registers and authenticates users with a phone number and a one-time code. You supply the SMS delivery function. KavachOS handles code generation, expiry, and rate limiting.

Setup

lib/kavach.ts
Mount the handler the same way as any other plugin, see adapters.

Send code

POST /auth/phone/send-code Sends a one-time code to the given phone number. Creates the user account on first send.
Send code (client)
Phone numbers must be in E.164 format (+ prefix, country code, number). Error codes

Verify code

POST /auth/phone/verify-code Submits the code the user received. Returns a session on success.
Verify code (client)
Error codes

Configuration reference

required
Callback invoked to deliver the code. Receives the phone number (E.164) and the numeric code as a string.
number
default:6
Number of digits in the generated code.
number
default:"300 (5 min)"
Code validity window in seconds.
number
default:5
Failed attempts allowed before the code is invalidated.
Last modified on April 29, 2026