Skip to content
FlanZ edited this page May 2, 2024 · 3 revisions

Welcome to Verif's Wiki 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.

Quick Start

Install Verif with npm to get started:

npm install verif

Core Concepts

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.

How It Works

Sending Verification Codes

Email Verification

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!');

SMS Verification with Twilio

const { sendTwilioMessage } = require('verif');

// Send a verification SMS
sendTwilioMessage('yourTwilioSID', 'yourTwilioToken', '+123456789', '+987654321');

SMS Verification with Vonage

const { sendVonageMessage } = require('verif');

// Send a verification SMS
sendVonageMessage('yourVonageAppId', 'path/to/private.key', 'Verif', '+987654321');

Verifying the Code

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.');

Extending CodeStore

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
    }
}

Need Help?

If you encounter any issues or have questions, please open an issue on our GitHub repository.

License

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!