-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Verif is a robust NPM module crafted to streamline the verification process using 6-digit codes. It's perfect for adding an extra layer of security through email or SMS, and it's powered by Twilio and Vonage for SMS services.
Install Verif with npm to get started:
npm install verif
CodeStore: At the heart of Verif is the CodeStore
, an abstract class that defines how verification codes are stored and verified. Extend this to create your own storage mechanism!
JsonFileCodeStore: A built-in implementation of CodeStore
that uses a JSON file. Simple and effective for quick setups.
Sending Verification Codes
const { createTransporter, sendMail } = require('verif');
// Set up your email transporter
const emailTransporter = createTransporter('smtp.example.com', 587, false, 'user@example.com', 'password');
// Send a verification email
sendMail(emailTransporter, 'from@example.com', 'to@example.com', 'Verify Your Account', 'Here is your verification code:', 'Thank you for choosing us!');
const { sendTwilioMessage } = require('verif');
// Send a verification SMS
sendTwilioMessage('yourTwilioSID', 'yourTwilioToken', '+123456789', '+987654321');
const { sendVonageMessage } = require('verif');
// Send a verification SMS
sendVonageMessage('yourVonageAppId', 'path/to/private.key', 'Verif', '+987654321');
const { verifyCode, JsonFileCodeStore } = require('verif');
// Create a code store instance
const codeStore = new JsonFileCodeStore();
// Verify the code sent to the user
const isCodeValid = verifyCode('user@example.com', '123456', codeStore);
console.log(isCodeValid ? 'Code is valid!' : 'Invalid code.');
Want to use a database or a different kind of storage? Here's how you can extend CodeStore
:
const { CodeStore } = require('verif');
class MyCustomCodeStore extends CodeStore {
storeCode(id, code) {
// Implement storing code logic here
}
verifyCode(id, code) {
// Implement code verification logic here
}
}
If you encounter any issues or have questions, please open an issue on our GitHub repository.
Verif is open-sourced under the MIT license. Feel free to use it in your projects!
Created with ❤️ by FlanZ. For more cool projects, follow me on GitHub!