Skip to content

Latest commit

 

History

History
 
 

magic-links

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

"Magic Link" Email Verification

These function show you how to send one-click email verification using Twilio Verify.

magic-link-demo.gif

How to use the template

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.

Pre-requisites

Follow steps 1-6 in the documentation to link your SendGrid account to your Twilio Verify Service.

Important - for Step #4 use this file as a template.

All steps are described in detail in the documentation.

Environment variables

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
CALLBACK_PATH URL path linked in the email template to check verifications Yes

Function Parameters

start-verify.js expects the following parameters:

Parameter Description Required
to Email Yes

check-verify.js expects the following parameters:

Parameter Description Required
to Email Yes
verification_code Populated by SendGrid email template Yes

Create a new project with the template

  1. Install the Twilio CLI
  2. Install the serverless toolkit
twilio plugins:install @twilio-labs/plugin-serverless
  1. Initiate a new project
twilio serverless:init magic-links --template=magic-links && cd magic-links
  1. Add your environment variables to .env:

Make sure variables are populated in your .env file. See Environment variables.

  1. Start the server :
npm start
  1. Open the web page at https://localhost:3000/index.html and enter your email to test

ℹ️ Check the developer console and terminal for any errors, make sure you've set your environment variables.

Deploying

Deploy your functions and assets with the following command. Note: you must run these commands from inside your project folder. More details in the docs.

With the Twilio CLI:

twilio serverless:deploy