top of page

SMS Verification in Wix Velo with Twilio Verify

Writer: Faysal Jaali
Faysal Jaali
Nov 15, 2024
3 min read

Updated: Nov 2

For SMS verification in Wix, use a service that issues and validates one-time codes on the backend. Generating a code with Math.random() and comparing it only in browser code is not a secure verification design.


This example uses Twilio Verify for a controlled administrator test. Phone verification establishes evidence of access to a number; it does not automatically create a Wix login session or authorize a purchase.


illustration sms code codemasters

Configure the verification service


Create a Twilio Verify Service configured for six-digit codes and review its supported countries, trial restrictions, fraud controls and current pricing. Obtain the Account SID, Auth Token and Verify Service SID.


Store them in Wix Secrets Manager as TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN and TWILIO_VERIFY_SERVICE_SID. Install the supported twilio npm package in the Wix development environment.


Twilio’s Node Verify quickstart and Verification Check reference document code issuance and checking. The code below adapts those calls to a Wix backend.


Start and check a verification


Create backend/phone-verification.web.js:


// backend/phone-verification.web.js
import { webMethod, Permissions } from "@wix/web-methods";
import { secrets } from "@wix/secrets";
import { auth } from "@wix/essentials";
import twilio from "twilio";

const readSecret = auth.elevate(secrets.getSecretValue);

function phone(value) {
  if (typeof value !== "string" || !/^\+[1-9]\d{7,14}$/.test(value)) {
    throw new Error("Use an international phone number in E.164 format.");
  }
  return value;
}

async function verifyService() {
  const [sid, token, service] = await Promise.all([
    readSecret("TWILIO_ACCOUNT_SID"),
    readSecret("TWILIO_AUTH_TOKEN"),
    readSecret("TWILIO_VERIFY_SERVICE_SID")
  ]);
  return twilio(sid.value, token.value).verify.v2.services(service.value);
}

export const startPhoneVerification = webMethod(
  Permissions.Admin,
  async to => {
    const number = phone(to);
    const service = await verifyService();
    try {
      const result = await service.verifications.create({ to: number, channel: "sms" });
      return { requested: result.status === "pending" };
    } catch {
      throw new Error("The verification request could not be started.");
    }
  }
);

export const checkPhoneVerification = webMethod(
  Permissions.Admin,
  async (to, code) => {
    const number = phone(to);
    if (typeof code !== "string" || !/^\d{6}$/.test(code)) {
      throw new Error("Enter the six-digit code.");
    }
    const service = await verifyService();
    try {
      const result = await service.verificationChecks.create({ to: number, code });
      return { approved: result.status === "approved" };
    } catch {
      throw new Error("The verification request could not be checked.");
    }
  }
);

The Wix web-method permission is Admin for both functions. Use a test number you control and are authorized to message. No actual SMS messages were sent during the article review.


The example checks a six-digit code because that is the specified test configuration. Adapt the validation deliberately if the service is configured differently.


Keep approval on the backend


For a production flow, bind the destination and verification to the authenticated user or verified server-side session. Retrieve that state from trusted records when checking the code.


Do not trust an approved flag sent back from the browser. The protected business action must independently verify the approved state and its intended purpose.


Use the appropriate Wix member authentication workflow when the requirement is login. A standalone SMS example is not a complete multi-factor authentication system.


screenshot adding twilio.web.js In the Backend  of WIx
Original Wix backend-file illustration. Use the current Verify-based code and configuration described in this guide.

Add controls before public access


Do not change both methods to Anyone and publish an unrestricted SMS endpoint. Design per-user and per-destination limits, resend behaviour, attempt limits and fraud monitoring.


Explain why the number is being requested and handle it according to the applicable privacy requirements. Avoid logging full phone numbers, codes or provider credentials.


Test meaningful failures


Test malformed numbers, incorrect codes, expired requests, provider errors and repeated attempts. Check that an approval cannot be reused for another number or action.


Local tests checked validation, admin permission, provider-call arguments and approval handling with a simulated Twilio client. Billing, delivery, fraud controls and production session binding require project-specific verification.


Does the frontend decide that the phone is verified?


No. Treat the frontend as an interface to a backend-controlled process.


Does SMS verification prove someone’s legal identity?


It is evidence about access to a destination, not a universal identity check.


For related backend examples, see triggered emails or contact CodeMasters.

bottom of page