Note: This package is still under heavy development and methods can change at any point in time. Use with caution. Contributors welcome.
Serify is a wrapper around the Twilio VerifyREST API. This lightweight and straightforward wrapper allows you to send and verify SMS codes with two easy to use methods – and it only has two dependencies. Both methods use of async/await, making it easy to integrate into your existing codebase.
Note: The phone number is automatically converted when passing an ISO-3166 country code. For example, when passing
USAas the country, the library will automatically validate and construct a valid phone number such as +15554443333.
To send a verification code using, use the start method as shown below:
importSerifyfrom'serify';constauth=newSerify({twilioServiceSid: 'YOUR_TWILIO_SERVICE_SID',// required (found in the twilio console)twilioAccountSid: 'YOUR_TWILIO_ACCOUNT_SID',// required (found in the twilio console)twilioAuthToken: 'YOUR_TWILIO_AUTH_TOKEN',// required (found in the twilio console)});conststart=async()=>{try{conststart=awaitauth.start({phone: 'USER_PHONE_NUMBER',// users phone number in E.164 formatcountry: 'USA',// ISO-3166 alpha 3 format (e.g. USA, CAN, etc.)});console.log(start);}catch(error){console.log(error);}};start();To verify a code, use the verify method as shown below:
importSerifyfrom'serify';constauth=newSerify({twilioServiceSid: 'YOUR_TWILIO_SERVICE_SID',// required (found in the twilio console)twilioAccountSid: 'YOUR_TWILIO_ACCOUNT_SID',// required (found in the twilio console)twilioAuthToken: 'YOUR_TWILIO_AUTH_TOKEN',// required (found in the twilio console)});constverify=async()=>{try{constverify=awaitauth.verify({phone: 'USER_PHONE_NUMBER',// users phone number in E.164 formatcountry: 'USA',// ISO-3166 alpha 3 format (e.g. USA, CAN, etc.)code: '1990',// length is configurable via the twilio console});console.log(verify);}catch(error){console.log(error);}};verify();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.
- The account level SID and Account Auth Token are provided at the top level of your account.
- The service specific SID can be found when creating your application for the Twilio Verify product.
