auth-verify 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +119 -0
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "sqlite3": "^5.1.7"
7
7
  },
8
8
  "name": "auth-verify",
9
- "version": "0.0.1",
9
+ "version": "0.0.2",
10
10
  "description": "A simple Node.js library for sending and verifying OTP via email",
11
11
  "main": "index.js",
12
12
  "devDependencies": {},
package/readme.md ADDED
@@ -0,0 +1,119 @@
1
+ # auth-verify
2
+
3
+ `auth-verify` is a **Node.js library** for handling **OTP (One-Time Password) generation, email verification, and expiration tracking**. It provides secure OTP generation, rate-limiting, cooldowns, and integration with **Nodemailer** for sending verification emails.
4
+
5
+ ---
6
+
7
+ ## Features
8
+
9
+ - Generate secure OTP codes
10
+ - Send OTP via **email** using Nodemailer
11
+ - Verify OTP codes with expiration checks
12
+ - Limit OTP requests per day and enforce cooldowns
13
+ - Store OTPs in a **SQLite database**
14
+ - Fully asynchronous with callback support
15
+
16
+ ---
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install auth-verify
22
+ ```
23
+ ### 🚀 Quick Start
24
+
25
+ ##### 1. Initialize Verifier
26
+ ```js
27
+ const Verifier = require('auth-verify');
28
+
29
+ const verifier = new Verifier({
30
+ sender: 'your_email@example.com',
31
+ pass: 'your_email_password',
32
+ serv: 'gmail', // SMTP service name
33
+ otp: {
34
+ leng: 6, // OTP length (default: 6)
35
+ expMin: 3, // OTP expiration in minutes (default: 3)
36
+ limit: 5, // Max requests per day (default: 5)
37
+ cooldown: 60 // Cooldown between requests in seconds (default: 60)
38
+ }
39
+ });
40
+ ```
41
+ ##### 2. Send OTP
42
+ ```js
43
+ verifier
44
+ .html("<h1>Your OTP is {otp}</h1>") // optional HTML template
45
+ .subject("Verify your account: {otp}") // optional subject
46
+ .text("Your OTP is {otp}") // optional plain text
47
+ .sendTo('user@example.com', (err, success) => {
48
+ if (err) return console.error(err);
49
+ console.log("OTP sent successfully!");
50
+ });
51
+ ```
52
+ ##### 3. Verify OTP
53
+ ```js
54
+ verifier.code('123456').verifyFor('user@example.com', (err, isValid) => {
55
+ if (err) return console.error(err);
56
+ console.log(isValid ? "✅ OTP verified" : "❌ Invalid or expired OTP");
57
+ });
58
+ ```
59
+ ##### 4. Get OTP Details (for testing/debugging)
60
+ ```js
61
+ verifier.getOTP('user@example.com', (err, data) => {
62
+ if (err) return console.error(err);
63
+ console.log(data); // { code: '123456', expiresAt: '2025-09-28T...' }
64
+ });
65
+ ```
66
+ ##### 5. Clean Expired OTPs
67
+ ```js
68
+ verifier.cleanExpired(); // Deletes expired OTPs from the database
69
+ ```
70
+ #### API Reference
71
+ `new Verifier(options)`
72
+
73
+ `sender` – sender email for Nodemailer
74
+
75
+ `pass` – email password
76
+
77
+ `serv` – SMTP service name
78
+
79
+ `otp` – object:
80
+
81
+ `leng` (number) – OTP length (default: 6)
82
+
83
+ `expMin` (number) – OTP expiration in minutes (default: 3)
84
+
85
+ `limit` (number) – Max requests per day (default: 5)
86
+
87
+ `cooldown` (number) – Cooldown in seconds between requests (default: 60)
88
+
89
+ #### Methods
90
+
91
+ `html(content)` – Sets optional HTML content with {otp} placeholder
92
+
93
+ `subject(content)` – Sets optional email subject with {otp} placeholder
94
+
95
+ `text(content)` – Sets optional plain text with {otp} placeholder
96
+
97
+ `sendTo(email, callback)` – Sends OTP to an email
98
+
99
+ `code(otp)` – Set user-provided OTP for verification
100
+
101
+ `verifyFor(email, callback)` – Verify OTP for the given email
102
+
103
+ `getOTP(email, callback)` – Retrieve OTP and expiration from DB
104
+
105
+ `cleanExpired()` – Delete expired OTPs from database
106
+
107
+ #### Database
108
+
109
+ Uses SQLite (authverify.db) to store:
110
+
111
+ Email
112
+
113
+ OTP code
114
+
115
+ Expiration timestamp
116
+
117
+ Request count
118
+
119
+ Last request timestamp