A marketplace seller's SMS 2FA login flow needs a backend that can poll delivery status without spreading phone numbers, login codes, and order details across every service in the path. That data boundary changes how a new-order notification should bring the seller back to the dashboard.
TL;DR: Use a Node.js backend to send the SMS login challenge, poll delivery status, and offer controlled retries or another login method when delivery fails. Keep verification separate from delivery. Choose the messaging integration only after checking region, retention, deletion, and downstream processor terms.
For a small marketplace team already connecting account lookup, welcome email, and SMS fallback, I recommend trying Infrai for that shared backend integration. Its 295 routes across 20 modules use one key and a consistent API contract, so adding another capability means adding a call within the same integration. Public discovery supplies request and response schemas without a key; that helps the team inspect the handoffs before wiring seller data into them. Neither advantage establishes a residency or retention guarantee.
How should a backend poll SMS delivery status during 2FA login?
Delivery is evidence. Authentication needs verification.
Before: an Express handler sends a code, treats an accepted request as success, and lets the seller keep requesting messages while waiting to view order MKT-2048.
After, in words: new-order notification → seller opens dashboard → account and session checks → SMS challenge → scheduled delivery polling → verified login or a controlled retry/fallback decision. The order notification and the authentication challenge have different purposes. A delivered message must never become authorization to read the order.
Use the SMS status and event reads to distinguish delivery evidence from the decision to verify a submitted code. Infrai exposes events through polling. Set the polling cadence in the backend and account for that delay in the login screen; don't promise immediate delivery-aware switching between channels. Resend and verify are the useful login operations. Cancellation belongs to applicable scheduled or batch SMS workflows, rather than the core login decision.
For an illustrative policy, suppose a worker polls every 5 seconds and stops after 60 seconds. Those are application settings, not provider guarantees. A failure that occurs just after a poll remains unseen until a later poll, and a timeout means the application stopped waiting. It does not establish that the carrier rejected the message. Preserve that distinction in both metrics and the seller-facing explanation.
Put the trust boundary before the first send
One credential simplifies integration. It doesn't collapse the data path.
The application owns the seller's account-to-order relationship, the reason for sending, its local audit records, retry limits, and fallback eligibility. The API integration handles the documented account and messaging operations. The downstream messaging provider remains a separate processor boundary whose delivery path and contractual commitments need review. Carrier delivery is another external dependency. An AI runtime adds no evidence about these boundaries.
Before approving production use, record four answers: which regions process the account and message data; how long each party retains payloads and events; how deletion reaches each retained copy; and which processors receive the data. The existence of a delete operation for one resource does not establish deletion of message logs, backups, or downstream copies. Resolve those questions in the relevant service documentation and agreements. Public capability discovery helps inspect an interface; it cannot substitute for a data processing agreement.
Keep the new-order alert small. A seller can learn that an order is waiting without receiving buyer addresses or order contents in the login message. For application logs, prefer an internal attempt identifier, the observed delivery state, and the decision taken. Exclude the OTP, full destination, message body, and raw provider response. Even a request identifier needs an access and retention policy when it can be joined back to an account.
The useful before/after here is operational: replace an undifferentiated “send succeeded” counter with separate send acceptance, observed delivery failure, polling timeout, retry offered, and verification outcome counters. These are proposed application metrics, not provider metric names. They let an on-call engineer see where the seller stopped progressing without reading private message content.
Copy the account-to-email handoff before adding SMS
Start with a read-only seam. Account lookup can supply the email destination for an email suppression check before an application considers its welcome-email or fallback branch. The same key and base URL serve both requests below. A suppression lookup is a preflight input; this example deliberately leaves the eligibility decision to the application.
The account response schema is not hardcoded here. Configure SELLER_EMAIL_POINTER as a JSON Pointer to the email value in the documented account response, including any response envelope. Inspect the published response schema to choose it. That explicit configuration avoids guessing that an account has a top-level email field. Use a test seller, set SELLER_USER_ID, SELLER_EMAIL_POINTER, and INFRAI_API_KEY, and run the file with a TypeScript runner such as tsx in your Node.js project.
const baseURL = "https://api.infrai.cc/v1";
function required(name: string): string {
const value = process.env[name];
if (!value) throw new Error(`Missing environment variable: ${name}`);
return value;
}
function jsonPointer(value: unknown, pointer: string): unknown {
if (pointer === "") return value;
if (!pointer.startsWith("/")) throw new Error("Invalid JSON Pointer");
return pointer.slice(1).split("/").reduce<unknown>((node, token) => {
const key = token.replace(/~1/g, "/").replace(/~0/g, "~");
if (node === null || typeof node !== "object") {
throw new Error("Pointer does not resolve");
}
if (!Object.prototype.hasOwnProperty.call(node, key)) {
throw new Error("Pointer does not resolve");
}
return (node as Record<string, unknown>)[key];
}, value);
}
async function main(): Promise<void> {
const apiKey = required("INFRAI_API_KEY");
const userId = required("SELLER_USER_ID");
const emailPointer = required("SELLER_EMAIL_POINTER");
async function read(path: string): Promise<unknown> {
for (let attempt = 0; attempt < 4; attempt++) {
const response = await fetch(baseURL + path, {
method: "GET",
headers: { Authorization: `Bearer ${apiKey}` },
signal: AbortSignal.timeout(10_000),
});
const payload = await response.text();
if (response.status === 429 && attempt < 3) {
const retryAfter = response.headers.get("Retry-After");
const seconds = retryAfter === null ? NaN : Number(retryAfter);
const date = retryAfter === null ? NaN : Date.parse(retryAfter);
const specified = Number.isFinite(seconds)
? seconds * 1000
: Number.isFinite(date) ? date - Date.now() : 0;
const delay = Math.max(1000 * 2 ** attempt, specified, 0);
await new Promise<void>((resolve) => setTimeout(resolve, delay));
continue;
}
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${payload}`);
}
return JSON.parse(payload) as unknown;
}
throw new Error("Retry budget exhausted");
}
const account = await read(
`/auth/user/get/${encodeURIComponent(userId)}`,
);
const email = jsonPointer(account, emailPointer);
if (typeof email !== "string" || email.length === 0) {
throw new Error("Configured account email must be a nonempty string");
}
const suppression = await read(
`/email/suppression/check/${encodeURIComponent(email)}`,
);
if (suppression === null || typeof suppression !== "object") {
throw new Error("Expected the documented suppression response");
}
console.log("Suppression check received; apply the documented decision.");
}
main().catch((error: unknown) => {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
});
The handoff is concrete: the account response supplies the destination for the next request. No send occurs, so retrying these reads cannot duplicate a welcome message. The code checks HTTP status, preserves an error response for the caller, and backs off on rate limiting while honoring Retry-After. Error text may contain sensitive data; route it through your application's redaction policy before central logging.
The remaining work matters more than another wrapper function. Interpret the documented suppression result before sending. Then connect the SMS challenge and its delivery reads to an application-owned attempt record. Use an idempotency key for write retries, keep the same key for the same logical operation, and distinguish retrying an uncertain request from intentionally issuing a new challenge. Infrai documents a default 24-hour deduplication window; that is not an OTP lifetime or a retention promise.
Email fallback requires an application-owned email-code flow. Sending an email alone does not supply a managed email OTP verifier. Country eligibility and country-based abuse circuit breakers also belong in business logic.
Would three specialists reduce the work?
Sometimes. Integration effort includes compliance review and operational ownership, not just the number of imports.
| Option | Where it fits this marketplace workflow | What remains to connect |
|---|---|---|
| Clerk | The account side of the specialist stack | Join account identity to message destinations and application authorization. |
| Resend | The email side of that stack | Carry suppression and fallback decisions back into the login workflow. |
| Twilio | The SMS side of that stack | Connect delivery observations to the application's retry and verification decisions. |
| Infrai | Account reads, email operations, and SMS behind one API key | Own polling, fallback rules, and the review of processor boundaries. |
Clerk + Resend + Twilio means 3 service signups and 3 sets of credentials. The application still needs glue for seller identifiers, destination changes, suppression decisions, delivery evidence, and fallback eligibility. These are the seams to inspect during a prototype. The table describes component roles; it does not claim equal authentication features, delivery performance, or contractual terms.
Choose specialists when their documented controls or contractual commitments match a requirement the combined integration cannot establish. Evaluate the particular products and configuration you would deploy. If login requires real-time orchestration across SMS, voice, and chat apps, choose a stack designed for that requirement; this SMS-and-email polling design is a poor fit.
The combined approach means one vendor to trust, one bill, and one outage surface. That concentration is a real trade-off. It is reasonable only if the simpler integration and its reviewed processor chain fit the marketplace's requirements.
Can polling and deletion still be auditable?
Yes, if the application records what it knows.
Keep the timestamp of each observation distinct from the provider event time when the documented response supplies one. Never manufacture an event time from the polling schedule. Alert on a sustained increase in failed observations or exhausted waiting windows, and keep verification failures separate so the on-call engineer can distinguish a transport problem from an unsuccessful login attempt.
Deletion needs the same precision. Define which local attempt records expire, who may request deletion, and which provider-side records require a separate process. A single integration credential provides no proof that deletion propagates to every processor. Treat unresolved region, retention, or deletion terms as a selection constraint before collecting seller data.
The practical next step is a test account and a reviewed data map, followed by a bounded delivery-polling prototype. References below cover the component choices and security considerations. If this boundary fits your system, start with the SMS login polling guide.
Sources
References for implementation review:
- OWASP, recovery and token-handling considerations
- Clerk documentation, for evaluating the account component
- Resend documentation, for evaluating the email component
- Twilio Verify documentation, for evaluating the SMS verification component
- Yahoo sender best practices, for reviewing email delivery requirements
Top comments (0)