Skip to contentSkip to navigationSkip to topbar

One-Time Passcode Verification (OTP)

Created by: Twilio
  • Verify
  • JavaScript
  • Popular
  • Quick Deploy

This app will show you an example of how to build a one-time passcode (OTP) experience using SMS, WhatsApp, voice, or email* with the Twilio Verify API(link takes you to an external page).

This sample uses function templates(link takes you to an external page) to quickly create and deploy serverless functions you can use to interface with the Twilio Verify API from your production application. The interface provided shows off available features including channel selection and language preference.

otp code exchange template view with phone number input and channel selection.

How it works:

  1. User enters their phone number or email
  2. App generates an authentication token
  3. App sends the token via selected channel to the user
  4. User enters the correct token
  5. App verifies the token

For more information, check out this blog post on serverless phone verification(link takes you to an external page). For interface best practices including retry logic and channel fallback, check out best practices for managing retry logic with SMS 2FA(link takes you to an external page).

*Note: email channel requires additional configuration, follow the instructions in the docs(link takes you to an external page).

Report this template(link takes you to an external page)
Quick Deploy to TwilioGet CodeUse Twilio CLI
Launch and test this app in a few minutes with Quick Deploy. No server needed. Quick Deploy will automatically configure and deploy this app using Twilio Functions. Learn more about Twilio Functions(link takes you to an external page)
  1. Log in to Twilio

    Access your Twilio account to get started.

    Checking for existing account...

  2. Verify Service SID

    SID of your Twilio Verify Service

  3. Click the button below to deploy your app

    This will use the details entered above to deploy your application to Twilio Functions.

    You will be able to view the application in the browser and edit it using the Functions UI.

Need some help?

We all do sometimes; code is hard. Get help now from our support team(link takes you to an external page), or lean on the wisdom of the crowd by browsing the Twilio tag(link takes you to an external page)on Stack Overflow.

Terms of servicePrivacy Policy

Copyright © 2025 Twilio Inc.