An open API service indexing awesome lists of open source software.

https://github.com/bcfchen/node-twilio-verify

node module for twilio phone number verification
https://github.com/bcfchen/node-twilio-verify

Last synced: 3 months ago
JSON representation

node module for twilio phone number verification

Awesome Lists containing this project

README

          

# node-twilio-verify
## Node module for twilio phone number verification via SMS

This module verifies the user's phone number by generating a unique code and sending it to the user's phone via SMS. The user then sends the code back to the node server, and if the two codes match, the user is verified.

Most of the logic behind this module came from mcwebb's [angular-twilio-verification] (https://github.com/mcwebb/angular-twilio-verification). This module adapted the logic to node for the sake of convenience.

**Note: you must have a Twilio account with a valid accountSid and authToken to use this module.**

### Install
You can either install it by itself via npm:
```
npm install node-twilio-verify
```
Or include it in your package.json dependencies:
```
"dependencies": {
........,
"node-twilio-verify": "1.0.0",
.......
}
```

### Setup
Require the module into your Node application with the line:
```
var TwilioAuthService = require('node-twilio-verify')
```
Create a new instance of TwilioAuthService, initialize with the accountSid, authToken, and set the "from" number that comes with your Twilio account:
```
var accountSid = "xxxxxxxx",
authToken = "yyyyyyyyyy",
fromNumber = '+1xxxxxxxxxx';

twilioAuthService = new TwilioAuthService();
twilioAuthService.init(accountSid, authToken);
twilioAuthService.setFromNumber(fromNumber);
```
### Use
Fire away with sendCode or verifyCode!!
```
twilioAuthService.sendCode(toNumber, msgBody).then(function(results) {
res.send(200, results);
}, function error(err) {
res.send(500, err);
});

var isValid = twilioAuthService.verifyCode(phoneNumber, code);
if (isValid){
res.send(200, "Validation success");
} else {
res.send(422, "Code validation failed");
}
```