Creating a Function
Verifying phone numbers with a Function.
The magic of Evervault is that although you never handle sensitive data in plaintext, you can still use and process it — without the risk of it being breached. This is where Evervault Functions come in. Functions are isolated serverless functions hosted on Evervault for processing the data you encrypt with Relay.
Now we’re going to create and deploy a Function to verify that the phone numbers submitted to your form are valid.
Creating a Function
First, in the Evervault Dashboard, create a Function using our GitHub integration. Select
Choose template and, then, authenticate with GitHub. For this, you’ll need a GitHub account — so, create a GitHub account if you haven't got one already. Once you’ve authenticated with GitHub, you can select the ‘Verify Phone’ Function template. This will automatically deploy a Function on Evervault and create a repository in your GitHub. We recommend naming the repo 'verify-phone-number'.
Navigate to your new repo in GitHub (the URL is available on your Function's page in the Evervault Dashboard). You’ll notice that the
index.js file contains the following code:
Verifying phone numbers
This Function uses the phone library to validate the phone number and returns the result.
Now that you know what the Function does, it’s time to run it. Update the
try block of your
POST /submit handler to contain the following:
Note: If you did not name your GitHub repo 'verify-phone-number', make sure you reference the correct repo in this snippet of code.
Complete the form hosted on your Relay domain again. In the Replit console, you should see
Verified or an error message returned. Notice that the phone number remains encrypted in the Console log.
Let’s summarize where you are. You’ve:
- Created an Express.js server (
- Created a HTML form for collecting a name and a phone number from a user (
- Connected your form to your server,
- Integrated Evervault Relay so that phone numbers submitted to your form are encrypted before they enter your server,
- Included the Evervault SDK so that outbound requests from your server are automatically decrypted, and
- Deployed a Function to verify that phone numbers are valid.
Great! Now that you've used a Function to verify the user's phone number, it’s time to use Twilio to send them an SMS.