DEV Community

Otipi
Otipi

Posted on AI-assisted

Login codes for Israeli phone numbers in Node.js: SMS, a voice call fallback, and no code storage

If your users are in Israel, phone sign-in has three local catches:

  1. Price. Global SMS APIs bill in dollars per message part. Twilio charges $0.2575 for one SMS part to Israel (checked 17.11.2026), about 82 agorot. Hebrew text is UCS-2, so a code message with a link can easily become two parts.
  2. Sender rules. An alphanumeric sender like MyApp needs a checked sender in Israel, and marketing SMS must start with the word "פרסומת" and carry an opt-out.
  3. Kosher phones. Some users carry phones that do not receive SMS at all. SMS-only sign-in locks them out.

This post builds a small Express sign-in flow that sends the code by SMS, offers a phone call that reads the code aloud when the SMS does not arrive, and keeps no codes in your database.

The plan

Let the provider own the code: it generates it, stores it, counts attempts and expires it. Your server makes two calls: send and verify. I use Otipi here (I built it, disclosure at the end), but the shape is the same for most OTP APIs.

1. Normalize the number

People type 050-123-4567. Convert to E.164 and reject anything that is not an Israeli mobile before you call any API:

// 050-123-4567 -> +972501234567, or null
export function toIsraeliMobile(input) {
  const d = String(input ?? '').replace(/[\s\-().]/g, '');
  const e164 = d.startsWith('+') ? d : d.startsWith('0') ? `+972${d.slice(1)}` : `+${d}`;
  return /^\+9725\d{8}$/.test(e164) ? e164 : null;
}
Enter fullscreen mode Exit fullscreen mode

2. Send and verify

Plain fetch, Node 18+, no dependencies:

const API = 'https://otipi.co.il/v1';
const headers = {
  Authorization: `Bearer ${process.env.OTIPI_KEY}`, // sk_test_... while building
  'Content-Type': 'application/json',
};

export async function sendCode(to, channel = 'sms') {
  const res = await fetch(`${API}/otp/send`, {
    method: 'POST',
    headers,
    body: JSON.stringify({ to, app: 'MyApp', language: 'he', channel }),
  });
  const body = await res.json();
  if (!res.ok) {
    throw Object.assign(new Error(body.error.message), { code: body.error.code, status: res.status });
  }
  return body; // { id, status: 'pending', to, channel, expires_at, test_code? }
}

export async function verifyCode(to, code) {
  const res = await fetch(`${API}/otp/verify`, {
    method: 'POST',
    headers,
    body: JSON.stringify({ to, code }),
  });
  return res.json(); // { valid: true } or { valid: false, reason: 'wrong_code' }
}
Enter fullscreen mode Exit fullscreen mode

Defaults worth knowing: you can set the code length with length (4 to 8 digits), it lives 5 minutes unless you pass ttl_minutes (1 to 30), and can be tried 5 times. The SMS text comes from a ready-made template in Hebrew, Arabic, Russian or English, with your app name in it, so you do not write or translate it.

If you prefer an SDK, npm install otipi (zero dependencies, TypeScript types):

import { Otipi } from 'otipi';
const otipi = new Otipi(process.env.OTIPI_KEY);

await otipi.otp.send({ to: '+972501234567', app: 'MyApp' });
const { valid } = await otipi.otp.verify({ to: '+972501234567', code: '482917' });
Enter fullscreen mode Exit fullscreen mode

3. The routes, with a voice fallback

The UI shows the code field, and after about 30 seconds a "Call me instead" button. The button hits the same route with voice: true:

import express from 'express';
import { toIsraeliMobile } from './phone.js';
import { sendCode, verifyCode } from './otp.js';

const app = express();
app.use(express.json());

app.post('/auth/code', async (req, res) => {
  const to = toIsraeliMobile(req.body.phone);
  if (!to) return res.status(400).json({ error: 'israeli_mobile_only' });

  try {
    const sent = await sendCode(to, req.body.voice ? 'voice' : 'sms');
    res.json({ ok: true, channel: sent.channel });
  } catch (err) {
    // too_many_codes: 5 codes an hour to one number
    // recipient_rate_limit: at most 3 SMS to one number in 10 minutes
    res.status(err.status === 429 ? 429 : 400).json({ error: err.code });
  }
});

app.post('/auth/verify', async (req, res) => {
  const to = toIsraeliMobile(req.body.phone);
  const result = await verifyCode(to, String(req.body.code ?? ''));
  if (!result.valid) return res.status(401).json({ error: result.reason });
  // the phone is proven: create your session here
  res.json({ ok: true });
});

app.listen(3000);
Enter fullscreen mode Exit fullscreen mode

With "channel": "voice" the person gets a call from an Israeli number, and a voice reads the digits twice, in Hebrew. A call counts as 2 SMS parts of the plan. That covers kosher phones and the cases where an SMS is late.

4. Let the phone fill the code in

  • Give the input autocomplete="one-time-code". iPhone offers the code from the SMS, and so does the Android keyboard.
  • Pass domain: 'myapp.co.il' to /otp/send. The SMS then ends with @myapp.co.il #123456, which Chrome on Android needs to fill the code in by itself, and iPhone will offer the code on that site only. In a Hebrew SMS this line can push the message to two parts.

5. Testing without a phone

A sk_test_ key is free, no card. In test mode /otp/send returns the code in test_code, so an end-to-end test can finish the whole flow:

import { test } from 'node:test';
import assert from 'node:assert';

test('sign-in flow', async () => {
  const sent = await sendCode('+972501234567');
  const result = await verifyCode('+972501234567', sent.test_code);
  assert.equal(result.valid, true);
});
Enter fullscreen mode Exit fullscreen mode

Test messages really arrive only on your own confirmed number (5 free SMS per account) and the account email; everything else stays in the log. Every answer says test_delivery: "real" or "sandbox".

Coming from Twilio Verify

Replace the Verify verifications call with /otp/send and the verification_checks call with /otp/verify. For 1000 codes a month at one part each, Twilio comes to about 820 ILS; on Otipi that volume fits the 2,000 SMS plan for 169 ILS a month. Plans are monthly in shekels: 500 SMS for 49 ILS, 2,000 for 169 ILS, 5,000 for 369 ILS, down to 6 agorot a part on the largest one. Past a plan, 10% more goes out and then sending stops: nothing is charged beyond it.

When Twilio is still the better choice: users in many countries. Otipi sends SMS to Israeli mobile numbers only.

Using Supabase instead?

Supabase Auth has a Send SMS hook: Supabase makes and checks the code, and the hook only delivers it. No backend, about five minutes: Supabase phone sign-in for Israel.


Disclosure: I build Otipi (otipi.co.il), an Israeli API for SMS, login codes and transactional email. Full reference for this flow: SMS verification codes (OTP) for Israeli apps. Price comparison: A Twilio alternative for Israel. SDK source: github.com/otipi-il/otipi-node.

Questions about phone sign-in for Israeli users are welcome in the comments.

Top comments (0)