DEV Community

Cover image for Announcing Serify: A Lightweight SMS Validation Library for Twilio Verify
Nick Parsons
Nick Parsons

Posted on • Originally published at npmjs.com

4 1

Announcing Serify: A Lightweight SMS Validation Library for Twilio Verify

Serify is a wrapper around the Twilio Verify REST API. This lightweight and straightforward wrapper allows you to send and verify SMS codes with two easy to use methods – and it only has one dependency. Both methods use of async/await, making it easy to integrate into your existing codebase.

Example

To send a verification code using, use the start method as shown below:

import Serify from 'serify';

const auth = new Serify({
    twilioServiceSid: 'YOUR_TWILIO_SERVICE_SID', // required
    twilioAccountSid: 'YOUR_TWILIO_ACCOUNT_SID', // required
    twilioAuthToken: 'YOUR_TWILIO_AUTH_TOKEN', // required
});

const start = async () => {
    try {
        const start = await auth.start({
            phone: 'USER_PHONE_NUMBER',
            country: 1,
        });

        console.log(start);
    } catch (error) {
        console.log(error);
    }
};

start();
Enter fullscreen mode Exit fullscreen mode

To verify a code, use the verify method as shown below:

import Serify from 'serify';

const auth = new Serify({
    twilioServiceSid: 'YOUR_TWILIO_SERVICE_SID', // required
    twilioAccountSid: 'YOUR_TWILIO_ACCOUNT_SID', // required
    twilioAuthToken: 'YOUR_TWILIO_AUTH_TOKEN', // required
});

const verify = async () => {
    try {
        const verify = await auth.verify({
            phone: 'USER_PHONE_NUMBER',
            country: 1,
            code: '1990',
        });

        console.log(verify);
    } catch (error) {
        console.log(error);
    }
};

verify();
Enter fullscreen mode Exit fullscreen mode

Obtaining Tokens

Twilio can be confusing at times as the API requires an Account Level SID, an Account Auth Token, in addition to a Service SID. All tokens can be found within your Twilio console.

  1. The account level SID and Account Auth Token are provided at the top level of your account.
  2. The service-specific SID can be found when creating your application for the Twilio Verify product.

https://www.npmjs.com/package/serify

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay