Skip to content

Verify: one-time codes ​

Goal: confirm a phone number at sign-up or log-in with a one-time code over SMS, WhatsApp or a voice call.

Price: verify.success per approved verification, plus the normal rate of the SMS / WhatsApp message / call that carried the code.

1. (Optional) create a profile ​

ts
const profile = await vi.verifyProfiles.create({
  name: "Login",
  app_name: "Acme",        // "Your Acme verification code is 123456…"
  code_length: 6,
  ttl_sec: 600,
  max_attempts: 5,
  channels: ["sms", "call", "whatsapp"],
  default_channel: "sms",
  whatsapp_template: "acme_otp", // an approved WhatsApp AUTHENTICATION template (required for WhatsApp)
  language: "he",
});

Without a profile, codes use the workspace name, 6 digits and 10 minutes. Messages are sent in Hebrew for Israeli workspaces and in English otherwise (language overrides).

2. Send a code ​

ts
const v = await vi.verifications.create({ to: "+972526543210", profile_id: profile.id }); // or channel: "call"

A new send cancels older pending codes for the same number and profile.

3. Check what the user typed ​

ts
const r = await vi.verifications.check(v.id, { code: "123456" });
if (r.valid) { /* signed in */ }
// or by number: await vi.verifications.checkByNumber({ to: "+972526543210", code: "123456" })

status is pending, approved, canceled, expired, max_attempts_reached or failed. Wrong codes count toward max_attempts.

Webhook events ​

Subscribe a webhook endpoint to verification.sent, verification.approved and verification.failed (reason: max_attempts_reached or a delivery error). data carries verification_id, to, channel, status, profile_id and the metadata you sent.

Custom message text ​

Set message_template on a profile, e.g. "{app}: {code} is your login code. Valid {minutes} min.". {code} is required; the same text (with digits spoken one by one, twice) is used for voice codes. WhatsApp always uses your approved template.

Safety built in ​

  • Codes are never stored, only an HMAC of them.
  • SMS pumping protection: at most 5 sends per number per 10 minutes and 15 per day; 1,000 per workspace per hour (429 rate_limited).
  • Numbers on the workspace do-not-call list are refused.
  • Test mode: test workspaces deliver nothing and return the code as test_code.