mbkauthe 2.5.0 → 3.0.0
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.
- package/LICENSE +339 -373
- package/README.md +106 -285
- package/docs/api.md +139 -1
- package/docs/db.md +1 -1
- package/docs/error-messages.md +557 -0
- package/index.d.ts +233 -0
- package/index.js +43 -32
- package/lib/config/cookies.js +52 -0
- package/lib/{config.js → config/index.js} +15 -95
- package/lib/config/security.js +8 -0
- package/lib/{pool.js → database/pool.js} +1 -1
- package/lib/main.js +27 -1041
- package/lib/{validateSessionAndRole.js → middleware/auth.js} +5 -3
- package/lib/middleware/index.js +106 -0
- package/lib/routes/auth.js +521 -0
- package/lib/routes/misc.js +272 -0
- package/lib/routes/oauth.js +325 -0
- package/lib/utils/errors.js +257 -0
- package/lib/utils/response.js +21 -0
- package/package.json +5 -2
- package/public/main.js +4 -4
- package/views/Error/dError.handlebars +1 -1
- package/views/errorCodes.handlebars +341 -0
- package/views/showmessage.handlebars +7 -6
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# MBKAuthe - Authentication System for Node.js
|
|
1
|
+
# MBKAuthe v3.0 - Authentication System for Node.js
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/mbkauthe)
|
|
4
|
-
[](LICENSE)
|
|
5
5
|
[](https://nodejs.org/)
|
|
6
6
|
[](https://github.com/MIbnEKhalid/mbkauthe/actions/workflows/publish.yml)
|
|
7
7
|
[](https://github.com/MIbnEKhalid/mbkauthe/actions/workflows/codeql.yml)
|
|
@@ -16,22 +16,19 @@
|
|
|
16
16
|
<img height="48px" src="https://handlebarsjs.com/handlebars-icon.svg" alt="Handlebars" />
|
|
17
17
|
</p>
|
|
18
18
|
|
|
19
|
-
**MBKAuth** is a
|
|
19
|
+
**MBKAuth v3.0** is a production-ready authentication system for Node.js applications. Built with Express and PostgreSQL, it provides secure authentication, 2FA, role-based access, and GitHub OAuth out of the box.
|
|
20
20
|
|
|
21
|
-
## ✨ Features
|
|
21
|
+
## ✨ Key Features
|
|
22
22
|
|
|
23
|
-
- 🔐
|
|
24
|
-
- 🔑
|
|
25
|
-
- 📱
|
|
26
|
-
- 🔄
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
- 🚀 **Easy Integration** - Drop-in authentication for Express.js apps
|
|
33
|
-
- 📊 **Database-Driven** - PostgreSQL for user and session management
|
|
34
|
-
- 🎨 **Customizable Views** - Handlebars templates for login/2FA pages
|
|
23
|
+
- 🔐 Secure password authentication with PBKDF2 hashing
|
|
24
|
+
- 🔑 PostgreSQL session management with cross-subdomain support
|
|
25
|
+
- 📱 Optional TOTP-based 2FA with trusted device memory
|
|
26
|
+
- 🔄 GitHub OAuth integration
|
|
27
|
+
- 👥 Role-based access control (SuperAdmin, NormalUser, Guest)
|
|
28
|
+
- 🎯 Multi-application user management
|
|
29
|
+
- 🛡️ CSRF protection & rate limiting
|
|
30
|
+
- 🚀 Easy Express.js integration
|
|
31
|
+
- 🎨 Customizable Handlebars templates
|
|
35
32
|
|
|
36
33
|
## 📦 Installation
|
|
37
34
|
|
|
@@ -41,72 +38,51 @@ npm install mbkauthe
|
|
|
41
38
|
|
|
42
39
|
## 🚀 Quick Start
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Create a `.env` file in your project root:
|
|
41
|
+
**1. Configure Environment (.env)**
|
|
47
42
|
|
|
48
43
|
```env
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
MAIN_SECRET_TOKEN=your-api-secret-token
|
|
44
|
+
APP_NAME=your-app
|
|
45
|
+
SESSION_SECRET_KEY=your-secret-key
|
|
46
|
+
MAIN_SECRET_TOKEN=api-token
|
|
53
47
|
IS_DEPLOYED=false
|
|
54
48
|
DOMAIN=localhost
|
|
49
|
+
LOGIN_DB=postgresql://user:pass@localhost:5432/db
|
|
55
50
|
|
|
56
|
-
#
|
|
57
|
-
LOGIN_DB=postgresql://username:password@localhost:5432/database_name
|
|
58
|
-
|
|
59
|
-
# Optional Features
|
|
51
|
+
# Optional
|
|
60
52
|
MBKAUTH_TWO_FA_ENABLE=false
|
|
61
53
|
COOKIE_EXPIRE_TIME=2
|
|
62
|
-
DEVICE_TRUST_DURATION_DAYS=7
|
|
63
|
-
|
|
64
|
-
# GitHub OAuth (Optional)
|
|
65
54
|
GITHUB_LOGIN_ENABLED=false
|
|
66
|
-
GITHUB_CLIENT_ID=your-github-oauth-client-id
|
|
67
|
-
GITHUB_CLIENT_SECRET=your-github-oauth-client-secret
|
|
68
55
|
```
|
|
69
56
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
### 2. Set Up Database
|
|
73
|
-
|
|
74
|
-
Create the required tables in your PostgreSQL database. See [Database Structure Documentation](docs/db.md) for complete schemas.
|
|
57
|
+
**2. Set Up Database**
|
|
75
58
|
|
|
76
59
|
```sql
|
|
77
|
-
-- Users table
|
|
78
60
|
CREATE TYPE role AS ENUM ('SuperAdmin', 'NormalUser', 'Guest');
|
|
79
61
|
|
|
80
62
|
CREATE TABLE "Users" (
|
|
81
63
|
id SERIAL PRIMARY KEY,
|
|
82
64
|
"UserName" VARCHAR(50) NOT NULL UNIQUE,
|
|
83
65
|
"Password" VARCHAR(61) NOT NULL,
|
|
84
|
-
"Role" role DEFAULT 'NormalUser'
|
|
66
|
+
"Role" role DEFAULT 'NormalUser',
|
|
85
67
|
"Active" BOOLEAN DEFAULT FALSE,
|
|
86
68
|
"AllowedApps" JSONB DEFAULT '["mbkauthe"]',
|
|
87
69
|
"SessionId" VARCHAR(213),
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"last_login" TIMESTAMP WITH TIME ZONE
|
|
70
|
+
created_at TIMESTAMP DEFAULT NOW(),
|
|
71
|
+
updated_at TIMESTAMP DEFAULT NOW()
|
|
91
72
|
);
|
|
92
|
-
|
|
93
|
-
-- Session table (created automatically by connect-pg-simple)
|
|
94
|
-
-- TwoFA table (optional, if 2FA is enabled)
|
|
95
|
-
-- TrustedDevices table (optional, for "Remember this device" feature)
|
|
96
|
-
-- user_github table (optional, for GitHub OAuth integration)
|
|
97
73
|
```
|
|
98
74
|
|
|
99
|
-
|
|
75
|
+
See [docs/db.md](docs/db.md) for complete schemas.
|
|
76
|
+
|
|
77
|
+
**3. Integrate with Express**
|
|
100
78
|
|
|
101
79
|
```javascript
|
|
102
80
|
import express from 'express';
|
|
103
|
-
import mbkauthe from 'mbkauthe';
|
|
104
|
-
import { validateSession, checkRolePermission } from 'mbkauthe';
|
|
81
|
+
import mbkauthe, { validateSession, checkRolePermission } from 'mbkauthe';
|
|
105
82
|
import dotenv from 'dotenv';
|
|
106
83
|
|
|
107
84
|
dotenv.config();
|
|
108
85
|
|
|
109
|
-
// Set mbkauthe configuration
|
|
110
86
|
process.env.mbkautheVar = JSON.stringify({
|
|
111
87
|
APP_NAME: process.env.APP_NAME,
|
|
112
88
|
SESSION_SECRET_KEY: process.env.SESSION_SECRET_KEY,
|
|
@@ -114,123 +90,84 @@ process.env.mbkautheVar = JSON.stringify({
|
|
|
114
90
|
IS_DEPLOYED: process.env.IS_DEPLOYED,
|
|
115
91
|
DOMAIN: process.env.DOMAIN,
|
|
116
92
|
LOGIN_DB: process.env.LOGIN_DB,
|
|
117
|
-
|
|
118
|
-
COOKIE_EXPIRE_TIME: process.env.COOKIE_EXPIRE_TIME || 2,
|
|
119
|
-
DEVICE_TRUST_DURATION_DAYS: process.env.DEVICE_TRUST_DURATION_DAYS || 7,
|
|
120
|
-
GITHUB_LOGIN_ENABLED: process.env.GITHUB_LOGIN_ENABLED,
|
|
121
|
-
GITHUB_CLIENT_ID: process.env.GITHUB_CLIENT_ID,
|
|
122
|
-
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET,
|
|
123
|
-
loginRedirectURL: '/dashboard' // Redirect after successful login
|
|
93
|
+
loginRedirectURL: '/dashboard'
|
|
124
94
|
});
|
|
125
95
|
|
|
126
96
|
const app = express();
|
|
127
97
|
|
|
128
|
-
// Mount
|
|
98
|
+
// Mount authentication routes
|
|
129
99
|
app.use(mbkauthe);
|
|
130
100
|
|
|
131
|
-
// Protected
|
|
101
|
+
// Protected routes
|
|
132
102
|
app.get('/dashboard', validateSession, (req, res) => {
|
|
133
103
|
res.send(`Welcome ${req.session.user.username}!`);
|
|
134
104
|
});
|
|
135
105
|
|
|
136
|
-
// Role-based route protection
|
|
137
106
|
app.get('/admin', validateSession, checkRolePermission(['SuperAdmin']), (req, res) => {
|
|
138
|
-
res.send('Admin
|
|
107
|
+
res.send('Admin Panel');
|
|
139
108
|
});
|
|
140
109
|
|
|
141
|
-
app.listen(3000
|
|
142
|
-
console.log('Server running on http://localhost:3000');
|
|
143
|
-
});
|
|
110
|
+
app.listen(3000);
|
|
144
111
|
```
|
|
145
112
|
|
|
146
|
-
##
|
|
113
|
+
## 📂 Architecture (v3.0)
|
|
147
114
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// User is authenticated
|
|
156
|
-
console.log(req.session.user); // { id, username, role, sessionId }
|
|
157
|
-
});
|
|
115
|
+
```
|
|
116
|
+
lib/
|
|
117
|
+
├── config/ # Configuration & security
|
|
118
|
+
├── database/ # PostgreSQL pool
|
|
119
|
+
├── utils/ # Errors & response helpers
|
|
120
|
+
├── middleware/ # Auth & session middleware
|
|
121
|
+
└── routes/ # Auth, OAuth, misc routes
|
|
158
122
|
```
|
|
159
123
|
|
|
160
|
-
|
|
161
|
-
|
|
124
|
+
**Key Improvements in v3.0:**
|
|
125
|
+
- Modular structure with clear separation of concerns
|
|
126
|
+
- Organized config, database, utils, middleware, and routes
|
|
127
|
+
- Better maintainability and scalability
|
|
162
128
|
|
|
163
|
-
|
|
164
|
-
app.get('/admin', validateSession, checkRolePermission(['SuperAdmin']), (req, res) => {
|
|
165
|
-
// Only SuperAdmin can access
|
|
166
|
-
});
|
|
167
|
-
```
|
|
129
|
+
## 🔧 Core API
|
|
168
130
|
|
|
169
|
-
|
|
170
|
-
Combined middleware for session validation and role checking.
|
|
131
|
+
### Middleware
|
|
171
132
|
|
|
172
133
|
```javascript
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
});
|
|
176
|
-
```
|
|
134
|
+
// Session validation
|
|
135
|
+
app.get('/protected', validateSession, handler);
|
|
177
136
|
|
|
178
|
-
|
|
179
|
-
|
|
137
|
+
// Role checking
|
|
138
|
+
app.get('/admin', validateSession, checkRolePermission(['SuperAdmin']), handler);
|
|
180
139
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
});
|
|
185
|
-
```
|
|
140
|
+
// Combined
|
|
141
|
+
import { validateSessionAndRole } from 'mbkauthe';
|
|
142
|
+
app.get('/mod', validateSessionAndRole(['SuperAdmin', 'NormalUser']), handler);
|
|
186
143
|
|
|
187
|
-
|
|
144
|
+
// API token auth
|
|
145
|
+
import { authenticate } from 'mbkauthe';
|
|
146
|
+
app.post('/api/data', authenticate(process.env.API_TOKEN), handler);
|
|
147
|
+
```
|
|
188
148
|
|
|
189
|
-
|
|
149
|
+
### Built-in Routes
|
|
190
150
|
|
|
191
151
|
- `GET /mbkauthe/login` - Login page
|
|
192
|
-
- `POST /mbkauthe/api/login` - Login endpoint
|
|
193
|
-
- `POST /mbkauthe/api/logout` - Logout endpoint
|
|
194
|
-
- `GET /mbkauthe/2fa` -
|
|
195
|
-
- `POST /mbkauthe/api/verify-2fa` - 2FA verification
|
|
196
|
-
- `GET /mbkauthe/api/github/login` -
|
|
197
|
-
- `GET /mbkauthe/
|
|
198
|
-
- `GET /mbkauthe/
|
|
199
|
-
- `POST /mbkauthe/api/terminateAllSessions` - Terminate all active sessions (authenticated)
|
|
152
|
+
- `POST /mbkauthe/api/login` - Login endpoint (8/min rate limit)
|
|
153
|
+
- `POST /mbkauthe/api/logout` - Logout endpoint (10/min rate limit)
|
|
154
|
+
- `GET /mbkauthe/2fa` - 2FA page (if enabled)
|
|
155
|
+
- `POST /mbkauthe/api/verify-2fa` - 2FA verification (5/min rate limit)
|
|
156
|
+
- `GET /mbkauthe/api/github/login` - GitHub OAuth
|
|
157
|
+
- `GET /mbkauthe/info` - Version & config info
|
|
158
|
+
- `GET /mbkauthe/ErrorCode` - Error documentation
|
|
200
159
|
|
|
201
160
|
## 🔐 Security Features
|
|
202
161
|
|
|
203
|
-
|
|
204
|
-
- **
|
|
205
|
-
- **
|
|
206
|
-
- **
|
|
207
|
-
- **
|
|
208
|
-
|
|
209
|
-
### CSRF Protection
|
|
210
|
-
All POST routes are protected with CSRF tokens. CSRF tokens are automatically included in rendered forms.
|
|
211
|
-
|
|
212
|
-
### Secure Cookies
|
|
213
|
-
- `httpOnly` flag prevents XSS attacks
|
|
214
|
-
- `sameSite: 'lax'` prevents CSRF attacks
|
|
215
|
-
- `secure` flag in production ensures HTTPS-only cookies
|
|
216
|
-
- Configurable expiration time
|
|
217
|
-
|
|
218
|
-
### Session Management
|
|
219
|
-
- PostgreSQL-backed persistent sessions
|
|
220
|
-
- Automatic session cleanup
|
|
221
|
-
- Session restoration from cookies
|
|
222
|
-
- Cross-subdomain session sharing (when deployed)
|
|
162
|
+
- **Rate Limiting**: Login (8/min), Logout (10/min), 2FA (5/min), OAuth (10/5min)
|
|
163
|
+
- **CSRF Protection**: All POST routes protected
|
|
164
|
+
- **Secure Cookies**: httpOnly, sameSite, secure in production
|
|
165
|
+
- **Password Hashing**: PBKDF2 with 100k iterations
|
|
166
|
+
- **Session Security**: PostgreSQL-backed, automatic cleanup
|
|
223
167
|
|
|
224
168
|
## 📱 Two-Factor Authentication
|
|
225
169
|
|
|
226
|
-
Enable
|
|
227
|
-
|
|
228
|
-
1. User logs in with username/password
|
|
229
|
-
2. If 2FA is enabled for the user, they're prompted for a 6-digit code
|
|
230
|
-
3. Code is verified using TOTP (Time-based One-Time Password)
|
|
231
|
-
4. Session is established after successful 2FA
|
|
232
|
-
|
|
233
|
-
### Database Setup for 2FA
|
|
170
|
+
Enable with `MBKAUTH_TWO_FA_ENABLE=true`:
|
|
234
171
|
|
|
235
172
|
```sql
|
|
236
173
|
CREATE TABLE "TwoFA" (
|
|
@@ -240,27 +177,20 @@ CREATE TABLE "TwoFA" (
|
|
|
240
177
|
);
|
|
241
178
|
```
|
|
242
179
|
|
|
243
|
-
|
|
180
|
+
Users can mark devices as trusted to skip 2FA for configurable duration.
|
|
244
181
|
|
|
245
|
-
|
|
246
|
-
Users can log in using their GitHub accounts if they have previously linked their GitHub account to their MBKAuth account.
|
|
182
|
+
## 🔄 GitHub OAuth
|
|
247
183
|
|
|
248
|
-
|
|
184
|
+
**Setup:**
|
|
249
185
|
|
|
250
|
-
1.
|
|
251
|
-
|
|
252
|
-
- Create a new OAuth App
|
|
253
|
-
- Set callback URL: `https://yourdomain.com/mbkauthe/api/github/login/callback`
|
|
254
|
-
- Copy Client ID and Client Secret
|
|
255
|
-
|
|
256
|
-
2. **Configure Environment**:
|
|
186
|
+
1. Create GitHub OAuth App with callback: `https://yourdomain.com/mbkauthe/api/github/login/callback`
|
|
187
|
+
2. Configure environment:
|
|
257
188
|
```env
|
|
258
189
|
GITHUB_LOGIN_ENABLED=true
|
|
259
|
-
GITHUB_CLIENT_ID=
|
|
260
|
-
GITHUB_CLIENT_SECRET=
|
|
190
|
+
GITHUB_CLIENT_ID=your_client_id
|
|
191
|
+
GITHUB_CLIENT_SECRET=your_client_secret
|
|
261
192
|
```
|
|
262
|
-
|
|
263
|
-
3. **Database Setup**:
|
|
193
|
+
3. Create table:
|
|
264
194
|
```sql
|
|
265
195
|
CREATE TABLE user_github (
|
|
266
196
|
id SERIAL PRIMARY KEY,
|
|
@@ -268,180 +198,71 @@ CREATE TABLE user_github (
|
|
|
268
198
|
github_id VARCHAR(255) UNIQUE,
|
|
269
199
|
github_username VARCHAR(255),
|
|
270
200
|
access_token VARCHAR(255),
|
|
271
|
-
created_at TIMESTAMP
|
|
272
|
-
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
|
201
|
+
created_at TIMESTAMP DEFAULT NOW()
|
|
273
202
|
);
|
|
274
|
-
|
|
275
|
-
CREATE INDEX idx_user_github_github_id ON user_github (github_id);
|
|
276
|
-
CREATE INDEX idx_user_github_user_name ON user_github (user_name);
|
|
277
203
|
```
|
|
278
204
|
|
|
279
|
-
### How It Works
|
|
280
|
-
|
|
281
|
-
1. User clicks "Login with GitHub" on the login page
|
|
282
|
-
2. User authenticates with GitHub
|
|
283
|
-
3. System verifies the GitHub account is linked to an active user
|
|
284
|
-
4. If 2FA is enabled, user is prompted for 2FA code
|
|
285
|
-
5. Session is established upon successful authentication
|
|
286
|
-
|
|
287
|
-
### Routes
|
|
288
|
-
|
|
289
|
-
- `GET /mbkauthe/api/github/login` - Initiates GitHub OAuth flow
|
|
290
|
-
- `GET /mbkauthe/api/github/login/callback` - Handles OAuth callback
|
|
291
|
-
|
|
292
|
-
## 🖥️ Trusted Devices (Remember Device)
|
|
293
|
-
|
|
294
|
-
### Overview
|
|
295
|
-
The "Remember this device" feature allows users to skip 2FA verification on trusted devices for a configurable duration.
|
|
296
|
-
|
|
297
|
-
### Configuration
|
|
298
|
-
|
|
299
|
-
```env
|
|
300
|
-
# Duration in days before device trust expires (default: 7 days)
|
|
301
|
-
DEVICE_TRUST_DURATION_DAYS=7
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
### Database Setup
|
|
305
|
-
|
|
306
|
-
```sql
|
|
307
|
-
CREATE TABLE "TrustedDevices" (
|
|
308
|
-
"id" SERIAL PRIMARY KEY,
|
|
309
|
-
"UserName" VARCHAR(50) NOT NULL REFERENCES "Users"("UserName") ON DELETE CASCADE,
|
|
310
|
-
"DeviceToken" VARCHAR(64) UNIQUE NOT NULL,
|
|
311
|
-
"DeviceName" VARCHAR(255),
|
|
312
|
-
"UserAgent" TEXT,
|
|
313
|
-
"IpAddress" VARCHAR(45),
|
|
314
|
-
"CreatedAt" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
|
315
|
-
"ExpiresAt" TIMESTAMP WITH TIME ZONE NOT NULL,
|
|
316
|
-
"LastUsed" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
|
317
|
-
);
|
|
318
|
-
|
|
319
|
-
CREATE INDEX idx_trusted_devices_token ON "TrustedDevices"("DeviceToken");
|
|
320
|
-
CREATE INDEX idx_trusted_devices_username ON "TrustedDevices"("UserName");
|
|
321
|
-
CREATE INDEX idx_trusted_devices_expires ON "TrustedDevices"("ExpiresAt");
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### How It Works
|
|
325
|
-
|
|
326
|
-
1. After successful login and 2FA verification, user can check "Remember this device"
|
|
327
|
-
2. A secure device token is generated and stored in cookies
|
|
328
|
-
3. On subsequent logins from the same device, 2FA is skipped
|
|
329
|
-
4. Device trust expires after configured duration
|
|
330
|
-
5. Users can manage trusted devices through their account settings
|
|
331
|
-
|
|
332
|
-
### Security Notes
|
|
333
|
-
|
|
334
|
-
- Device tokens are cryptographically secure (64-byte random tokens)
|
|
335
|
-
- Tokens automatically expire after the configured duration
|
|
336
|
-
- Last used timestamp is tracked for auditing
|
|
337
|
-
- IP address and user agent are stored for security monitoring
|
|
338
|
-
- Devices can be manually revoked by users
|
|
339
|
-
|
|
340
205
|
## 🎨 Customization
|
|
341
206
|
|
|
342
|
-
|
|
343
|
-
Set `loginRedirectURL` in `mbkautheVar`:
|
|
344
|
-
|
|
207
|
+
**Redirect URL:**
|
|
345
208
|
```javascript
|
|
346
209
|
process.env.mbkautheVar = JSON.stringify({
|
|
347
|
-
// ...
|
|
348
|
-
loginRedirectURL: '/dashboard'
|
|
210
|
+
// ...
|
|
211
|
+
loginRedirectURL: '/dashboard'
|
|
349
212
|
});
|
|
350
213
|
```
|
|
351
214
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
- `
|
|
355
|
-
- `
|
|
356
|
-
- `views/Error/dError.handlebars` - Error page
|
|
357
|
-
|
|
358
|
-
### Database Pool Access
|
|
359
|
-
Access the database pool for custom queries:
|
|
215
|
+
**Custom Views:** Create in `views/` directory:
|
|
216
|
+
- `loginmbkauthe.handlebars` - Login page
|
|
217
|
+
- `2fa.handlebars` - 2FA page
|
|
218
|
+
- `Error/dError.handlebars` - Error page
|
|
360
219
|
|
|
220
|
+
**Database Access:**
|
|
361
221
|
```javascript
|
|
362
222
|
import { dblogin } from 'mbkauthe';
|
|
363
|
-
|
|
364
|
-
const result = await dblogin.query('SELECT * FROM "Users" WHERE "UserName" = $1', [username]);
|
|
223
|
+
const result = await dblogin.query('SELECT * FROM "Users"');
|
|
365
224
|
```
|
|
366
225
|
|
|
367
226
|
## 🚢 Deployment
|
|
368
227
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
228
|
+
**Production Checklist:**
|
|
229
|
+
- ✅ Set `IS_DEPLOYED=true`
|
|
230
|
+
- ✅ Use strong secrets for SESSION_SECRET_KEY and Main_SECRET_TOKEN
|
|
231
|
+
- ✅ Enable HTTPS
|
|
232
|
+
- ✅ Configure correct DOMAIN
|
|
233
|
+
- ✅ Set appropriate COOKIE_EXPIRE_TIME
|
|
234
|
+
- ✅ Use environment variables for all secrets
|
|
372
235
|
|
|
236
|
+
**Vercel:**
|
|
373
237
|
```json
|
|
374
238
|
{
|
|
375
239
|
"version": 2,
|
|
376
|
-
"builds": [
|
|
377
|
-
|
|
378
|
-
"src": "index.js",
|
|
379
|
-
"use": "@vercel/node"
|
|
380
|
-
}
|
|
381
|
-
],
|
|
382
|
-
"routes": [
|
|
383
|
-
{
|
|
384
|
-
"src": "/(.*)",
|
|
385
|
-
"dest": "/index.js"
|
|
386
|
-
}
|
|
387
|
-
]
|
|
240
|
+
"builds": [{ "src": "index.js", "use": "@vercel/node" }],
|
|
241
|
+
"routes": [{ "src": "/(.*)", "dest": "/index.js" }]
|
|
388
242
|
}
|
|
389
243
|
```
|
|
390
244
|
|
|
391
|
-
### Production Checklist
|
|
392
|
-
|
|
393
|
-
- [ ] Set `IS_DEPLOYED=true`
|
|
394
|
-
- [ ] Use a strong `SESSION_SECRET_KEY` and `Main_SECRET_TOKEN`
|
|
395
|
-
- [ ] Enable HTTPS
|
|
396
|
-
- [ ] Set correct `DOMAIN`
|
|
397
|
-
- [ ] Enable 2FA for sensitive applications
|
|
398
|
-
- [ ] Configure `DEVICE_TRUST_DURATION_DAYS` appropriately
|
|
399
|
-
- [ ] Set up GitHub OAuth if using GitHub login
|
|
400
|
-
- [ ] Use environment variables for all secrets
|
|
401
|
-
- [ ] Set appropriate `COOKIE_EXPIRE_TIME`
|
|
402
|
-
- [ ] Configure PostgreSQL with proper security and indexes
|
|
403
|
-
- [ ] Enable password hashing with bcrypt
|
|
404
|
-
- [ ] Regularly audit and clean up expired trusted devices
|
|
405
|
-
|
|
406
245
|
## 📚 Documentation
|
|
407
246
|
|
|
408
|
-
- [API Documentation](docs/api.md) - Complete API reference
|
|
409
|
-
- [
|
|
410
|
-
- [
|
|
411
|
-
|
|
412
|
-
## 🔄 Version Check
|
|
413
|
-
|
|
414
|
-
MBKAuth automatically checks for updates on startup and warns if a newer version is available. Keep your package updated for security patches.
|
|
415
|
-
|
|
416
|
-
## 🤝 Contributing
|
|
417
|
-
|
|
418
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
419
|
-
|
|
420
|
-
1. Fork the repository
|
|
421
|
-
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
422
|
-
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
423
|
-
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
424
|
-
5. Open a Pull Request
|
|
247
|
+
- [API Documentation](docs/api.md) - Complete API reference
|
|
248
|
+
- [Database Guide](docs/db.md) - Schema details
|
|
249
|
+
- [Environment Config](docs/env.md) - Configuration options
|
|
425
250
|
|
|
426
251
|
## 📝 License
|
|
427
252
|
|
|
428
|
-
|
|
253
|
+
GNU General Public License v2.0 - see [LICENSE](LICENSE)
|
|
429
254
|
|
|
430
255
|
## 👨💻 Author
|
|
431
256
|
|
|
432
257
|
**Muhammad Bin Khalid**
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
## 🐛 Issues & Support
|
|
437
|
-
|
|
438
|
-
Found a bug or need help? Please [open an issue](https://github.com/MIbnEKhalid/mbkauthe/issues) on GitHub.
|
|
258
|
+
📧 [support@mbktech.org](mailto:support@mbktech.org) | [chmuhammadbinkhalid28@gmail.com](mailto:chmuhammadbinkhalid28@gmail.com)
|
|
259
|
+
🔗 [@MIbnEKhalid](https://github.com/MIbnEKhalid)
|
|
439
260
|
|
|
440
261
|
## 🔗 Links
|
|
441
262
|
|
|
442
263
|
- [npm Package](https://www.npmjs.com/package/mbkauthe)
|
|
443
264
|
- [GitHub Repository](https://github.com/MIbnEKhalid/mbkauthe)
|
|
444
|
-
- [
|
|
265
|
+
- [Issues & Support](https://github.com/MIbnEKhalid/mbkauthe/issues)
|
|
445
266
|
|
|
446
267
|
---
|
|
447
268
|
|