A verification link makes fintech signup easier to connect, but it also creates a decision: does opening the link confirm the phone number, or merely open the screen where the user enters an SMS code? Choose the second behavior for this implementation. TL;DR: bind each challenge to a signup session and destination, enforce resend cooldowns and verification rate limits on the server, and consume the challenge only after a correct code. The integration stays small because the application owns one explicit confirmation rule.

For a Node.js SMS OTP login API example, the useful starting point is that rule, before any delivery SDK. A message accepted for sending cannot authorize an account. Neither can a browser carrying an unrelated signup session.

Keep the boundary explicit.

The concrete job here is delivering a verification link during financial account signup. Healthcare appointment reminders raise a related distinction: confirming a destination does not establish permission to view someone's appointments. In either setting, destination confirmation and access authorization need separate decisions. This walkthrough implements the former; it does not establish financial identity or patient identity.

How should an SMS OTP login API bind cooldown and verify-code limits?

It should confirm the destination attached to the intended signup session. An opaque identifier in the verification link locates the challenge; the code supplies the secret. The server must still obtain the signup session from its authenticated session context, rather than trusting a session identifier submitted in a request body. Opening the link changes no verification state.

The data flow is deliberately short. A signup handler passes its session identifier and normalized phone number to the challenge service, which reserves a send and returns a private delivery payload containing the link and code. The transport delivers that payload. A verification handler later passes the server's session context, the challenge identifier, and the entered code back to the service; successful consumption produces a confirmation result for that session and phone number.

That last pair matters more than the transport response.

Use an acceptance matrix to settle the contract before connecting the SMS adapter. These are proposed application policies, not universal thresholds or measured results. The example uses six digits, a five-minute lifetime, a 60-second cooldown, three sends, and five failed comparisons per challenge. NIST's cited guidance supports single use, bounded validity, and rate limiting short authentication secrets; it also treats public telephone network delivery as restricted for authentication. These sample limits alone do not establish compliance.

Input or event Required result in this example Why it belongs in the contract
Link opened without a code No confirmation A page fetch must not consume the challenge
Correct code, different signup session Reject Confirmation must stay with its intended session
Resend before 60 seconds Reject A browser timer cannot enforce the send budget
Resend after two wrong guesses Preserve both failures Sending another message must not buy more guesses
Correct code after five failures Reject Knowledge of the code does not undo exhaustion
Correct code used twice Reject the second use Confirmation is a single transition

Make the acceptance contract executable

The following TypeScript example runs with a TypeScript runner configured for Node.js. It uses built-in modules and a fake delivery sink, so running it sends no SMS. It demonstrates the service behind request and verify handlers, rather than a public HTTP server. The link address is illustrative; it is not an external service dependency.

The in-memory store is a single-process test fixture. This approach is not suitable for multi-instance production deployments without shared storage. It doesn't support durable verification state across restarts. Its methods contain no asynchronous work, so the assertions can exercise the policy without a transport or database obscuring it.

import assert from "node:assert/strict"; import { createHmac, randomBytes, randomInt, timingSafeEqual } from "node:crypto"; type Delivery = { phone: string; link: string; code: string }; type Confirmation = { session: string; phone: string }; type Challenge = Confirmation & { id: string; digest: Buffer; deadline: number; nextSend: number; sends: number; failures: number; consumed: boolean; }; function createVerifier() { const key = randomBytes(32); const records = new Map<string, Challenge>(); const active = new Map<string, string>(); const digest = (id: string, code: string) => createHmac("sha256", key).update(`${id}:${code}`).digest(); function request(session: string, phone: string, now: number): Delivery | null { const scope = JSON.stringify([session, phone]); const current = active.get(scope); let row = current ? records.get(current) : undefined; if (row && now >= row.deadline) { records.delete(row.id); row = undefined; } if (row && (row.consumed || row.failures >= 5 || row.sends >= 3 || now < row.nextSend)) return null; if (!row) { const id = randomBytes(16).toString("hex"); row = { id, session, phone, digest: Buffer.alloc(32), deadline: now + 300_000, nextSend: now, sends: 0, failures: 0, consumed: false }; records.set(id, row); active.set(scope, id); } const code = randomInt(0, 1_000_000).toString().padStart(6, "0"); row.digest = digest(row.id, code); row.sends += 1; row.nextSend = now + 60_000; return { phone, link: `https://signup.example/verify?id=${row.id}`, code }; } function verify(session: string, id: string, code: string, now: number): Confirmation | null { const row = records.get(id); if (!row || row.session !== session || row.consumed || now >= row.deadline || row.failures >= 5) return null; if (!/^\d{6}$/.test(code) || !timingSafeEqual(row.digest, digest(id, code))) { row.failures += 1; return null; } row.consumed = true; return { session: row.session, phone: row.phone }; } return { request, verify }; } const service = createVerifier(); const session = "signup-fixture-01"; const phone = "+12025550123"; const first = service.request(session, phone, 0)!; const id = new URL(first.link).searchParams.get("id")!; const wrong = first.code === "000000" ? "000001" : "000000"; assert.equal(service.request(session, phone, 59_999), null); assert.equal(service.verify("another-session", id, first.code, 1), null); assert.equal(service.verify(session, id, wrong, 2), null); assert.equal(service.verify(session, id, wrong, 3), null); const resent = service.request(session, phone, 60_000)!; const wrongAgain = resent.code === "000000" ? "000001" : "000000"; for (let attempt = 0; attempt < 3; attempt += 1) { assert.equal(service.verify(session, id, wrongAgain, 60_001 + attempt), null); } assert.equal(service.verify(session, id, resent.code, 60_005), null); const next = service.request(session, phone, 300_000)!; const nextId = new URL(next.link).searchParams.get("id")!; assert.deepEqual(service.verify(session, nextId, next.code, 300_001), { session, phone }); assert.equal(service.verify(session, nextId, next.code, 300_002), null); 

The clock values are fixtures in milliseconds. Production handlers must supply server time, validate request sizes, normalize the phone number before lookup, and protect the signup session. The returned delivery object belongs inside the server's delivery workflow. Never return its code to the browser or put it in ordinary request logs.

A keyed digest keeps the comparison key separate from the stored challenge data. Here that key lives only for the fixture's lifetime; a persistent implementation needs a separately managed key that remains available for outstanding challenges. Losing it makes those comparisons impossible. The code is intentionally narrow: there is no account creation, HTTP middleware, storage cleanup, or authorization layer hidden inside it.

Treat changed destinations as a new approval decision

The awkward case is not a wrong code. It is a correct code arriving after the user edits the signup phone number.

The service returns the phone number stored when the challenge was created. The signup transaction must compare that destination with the current intended destination before recording confirmation. If the signup now targets a different number, reject the stale result and begin confirmation for the new destination. Do not reduce this result to a context-free true and mark whatever phone happens to be on the account as verified. That shortcut discards precisely the binding the challenge was meant to prove.

This is a security contract with a small integration surface. It also gives an LLM feature no role in the decision: a generated explanation can help a user understand the flow, but a model must not decide whether the secret matches or which account receives the result. Deterministic checks avoid adding model latency and token usage to this path. They are easier to audit, too.

Resends introduce a separate trade-off. This example replaces the comparison digest while preserving the original deadline and failed-attempt count. Only the latest issued code is intended to work; a delayed earlier message can therefore confuse the user. Keeping the same code across resends avoids that particular interaction, but requires the delivery workflow to retain a recoverable secret. Choose deliberately. A digest-only record can't reconstruct a code for another message.

There is also a boundary the fixture does not cover: a new challenge after expiry starts a new local budget. Before exposing signup publicly, enforce longer-lived limits across challenges and sessions for the destination, plus source and overall send limits. Otherwise an attacker can create fresh sessions to get fresh allowances. These additional counters must survive the lifetime of any one challenge; their thresholds depend on the application's abuse policy, not the numbers in this example.

Ship the binding through storage, delivery, and deployment

The first production integration should make the acceptance matrix true against real storage. Combine the session and destination check, attempt update, challenge consumption, and persisted signup confirmation in an atomic operation. Two simultaneous correct submissions must produce one consumption. A phone edit racing a successful verification must not leave the new destination confirmed by the old code. The in-memory fixture cannot establish either property across application instances.

Delivery adds another transaction boundary. Persist a send reservation and its outgoing job together, then let a worker call the transport. Keep retries of that job separate from explicit user resends: a worker retry should preserve the job's code and deadline, rather than minting another secret. A timeout can leave the worker uncertain whether the transport accepted a message. Plan for that ambiguity and use transport deduplication when available; an application queue alone does not promise exactly-once delivery.

That is extra integration work. It earns its place by making failure behavior reviewable.

Track send reservations, transport acceptance, rejected resends, failed comparisons, and successful consumption as distinct events. Use opaque correlation identifiers and reason categories; exclude codes, full verification links, and unnecessary personal data. Restrict and expire outgoing payloads because a worker needs the recoverable code even when the challenge table stores only its digest. Monitoring should help answer whether users are exhausting attempts or waiting for delivery without turning logs into another credential store.

Cost belongs at this boundary as a budget, rather than as a vendor ranking. Cap outbound work before reserving it, and observe duplicate jobs and abandoned signup attempts. An extra channel also creates another confirmation contract and more operational state. If email is added later, DMARC addresses domain authentication and policy; it does not prove that the signup user consumed a verification link. Treat that channel's confirmation semantics explicitly.

Before launch, run the matrix through the actual handlers and shared storage. Include expiry at exactly 300,000 milliseconds, resend at 59,999 and 60,000 milliseconds, a changed phone number, a wrong session, and concurrent successful submissions. Then interrupt a delivery worker after transport acceptance and before acknowledgment. Inspect the retry's payload and deadline. Roll out with send budgets and rejection monitoring active, and verify that deployment restarts preserve outstanding challenges and comparison keys.

The release decision is concrete: a successful code must confirm the intended signup and destination once, within the allowed lifetime and attempt budget. Ship when that statement survives the storage and delivery boundaries. A transport integration is only one part of the work.

Sources

References for the authentication and email-policy boundaries discussed above: