These functions show you how to create and check verification tokens for Twilio Verify using the Silent Network Auth channel.
The best way to use the Function templates is through the Twilio CLI as described below. If you'd like to use the template without the Twilio CLI, check out our usage docs.
- Create a Verify Service
- Create a Sync Service. You can also use the Default Service in your Twilio Console account.
- Create a Map in your Sync service.
This project requires some environment variables to be set. To keep your tokens and secrets secure, make sure to not commit the .env
file in git. When setting up the project with twilio serverless:init ...
the Twilio CLI will create a .gitignore
file that excludes .env
from the version history.
In your .env
file, set the following values:
Variable | Meaning | Required |
---|---|---|
ACCOUNT_SID |
Find in the console | Yes |
AUTH_TOKEN |
Find in the console | Yes |
VERIFY_SERVICE_SID |
Create one here | Yes |
SYNC_SERVICE_SID |
Create one here | Yes |
SYNC_MAP_SID |
Create one here | Yes |
verify-start.js
expects the following parameters:
Parameter | Description | Required |
---|---|---|
phoneNumber |
A phone number in E.164 format | Yes |
verify-check.js
expects the following parameters:
Parameter | Description | Required |
---|---|---|
phoneNumber |
A phone number in E.164 format | Yes |
- Install the Twilio CLI
- Install the serverless toolkit
twilio plugins:install @twilio-labs/plugin-serverless
- Initiate a new project
twilio serverless:init verify-sna-sample --template=verify-sna && cd verify-sna-sample
- Add your environment variables to
.env
:
Make sure variables are populated in your .env
file. See Environment variables.
- Start the server with the Twilio CLI:
twilio serverless:start
- Open the web page at https://localhost:3000/index.html and click the Fetch Verifications button to start waiting for created/checked verifications from the sample app
ℹ️ Check the developer console and terminal for any errors, make sure you've set your environment variables.
Deploy your functions and assets with either of the following commands. Note: you must run these commands from inside your project folder. More details in the docs.
With the Twilio CLI:
twilio serverless:deploy