Skip to contentSkip to navigationSkip to topbar

TOTP with SMS 2FA fallback

Created by: Twilio
  • Verify
  • JavaScript
  • Quick Deploy

This app will show you an example of how to build a time-based one-time passcode (TOTP) experience with fallback to SMS or WhatsApp using 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.

How it works:

  1. User verifies their phone number
  2. User sets up TOTP authentication with app of their choice
  3. User can log in with either method: TOTP or SMS/WhatsApp OTP

For more information, check out this overview of TOTP(link takes you to an external page). For more 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).

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.