secure-auth-kit 1.0.1 → 1.0.3

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/README.md +145 -0
  2. package/package.json +9 -3
package/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # Secure Auth Kit
2
+
3
+ Authentication toolkit for Express.js and MongoDB.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install secure-auth-kit
11
+ ```
12
+
13
+ ---
14
+
15
+ ## Quick Start
16
+
17
+ ```ts
18
+ import express from 'express';
19
+ import mongoose from 'mongoose';
20
+ import { secureAuth } from 'secure-auth-kit';
21
+ import { User } from './models/User.js';
22
+
23
+ const app = express();
24
+
25
+ app.use(express.json());
26
+
27
+ secureAuth(app, {
28
+ userModel: User,
29
+ jwt: {
30
+ secret: 'your_jwt_secret',
31
+ accessTokenExpiry: '15m', // default
32
+ refreshTokenExpiry: '7d', // default
33
+ },
34
+ });
35
+
36
+ app.listen(3000);
37
+ ```
38
+
39
+ This registers the following routes under `/auth` (configurable via `routePrefix`):
40
+
41
+ | Method | Route | Auth required |
42
+ | ------ | -------------- | ------------- |
43
+ | POST | /auth/register | No |
44
+ | POST | /auth/login | No |
45
+ | GET | /auth/me | Yes |
46
+
47
+ ---
48
+
49
+ ## User Model Requirements
50
+
51
+ Your Mongoose schema **must** have `email` and `password` fields. The package validates this at startup and throws a descriptive error if either is missing.
52
+
53
+ ```ts
54
+ // models/User.js
55
+ import mongoose from 'mongoose';
56
+
57
+ const userSchema = new mongoose.Schema({
58
+ email: {
59
+ type: String,
60
+ required: true,
61
+ unique: true,
62
+ },
63
+ password: {
64
+ type: String,
65
+ required: true,
66
+ },
67
+ });
68
+
69
+ export const User = mongoose.model('User', userSchema);
70
+ ```
71
+
72
+ `secure-auth-kit` will hash passwords on register and compare them on login - **never** store plaintext passwords yourself.
73
+
74
+ ---
75
+
76
+ ## Configuration
77
+
78
+ ```ts
79
+ secureAuth(app, {
80
+ userModel: User,
81
+
82
+ jwt: {
83
+ secret: 'your_jwt_secret',
84
+ accessTokenExpiry: '15m', // optional, default: '15m'
85
+ refreshTokenExpiry: '7d', // optional, default: '7d'
86
+ },
87
+
88
+ routePrefix: '/auth', // optional, default: '/auth'
89
+ });
90
+ ```
91
+
92
+ ---
93
+
94
+ ## `authenticate` Middleware
95
+
96
+ Protect any route by importing `authenticate`:,
97
+
98
+ ```ts
99
+ import { authenticate } from 'secure-auth-kit';
100
+
101
+ app.get('/protected', authenticate, (req, res) => {
102
+ res.json({ user: req.user });
103
+ });
104
+ ```
105
+
106
+ ---
107
+
108
+ ## API Reference
109
+
110
+ ### Routes
111
+
112
+ **POST /auth/register**
113
+
114
+ ```json
115
+ {
116
+ "email": "user@example.com",
117
+ "password": "Secret@123"
118
+ }
119
+ ```
120
+
121
+ Returns `{ user, tokens: { accessToken, refreshToken }}`
122
+
123
+ **POST /auth/login**
124
+
125
+ ```json
126
+ {
127
+ "email": "user@example.com",
128
+ "password": "Secret@123"
129
+ }
130
+ ```
131
+
132
+ Returns `{ user, tokens: { accessToken, refreshToken }}`
133
+
134
+ **GET /auth/me** _(requires Bearer token)_
135
+ </br>
136
+ Returns the current user (sanitized, no password).
137
+
138
+ ---
139
+
140
+ ## Security Notes
141
+
142
+ - Passwords are hashed with **bcrypt** (10 salt rounds).
143
+ - Access tokens default to **15 min** expiry; refresh tokens to **7 days**.
144
+
145
+ ---
package/package.json CHANGED
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "name": "secure-auth-kit",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Authentication toolkit for Express and MongoDB",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/SwapnilSahare45/secure-auth-kit"
8
+ },
9
+ "homepage": "https://github.com/SwapnilSahare45/secure-auth-kit#readme",
10
+ "author": "Swapnil Sahare",
5
11
  "type": "module",
6
12
  "main": "./dist/index.js",
7
13
  "types": "./dist/index.d.ts",
@@ -12,7 +18,8 @@
12
18
  }
13
19
  },
14
20
  "files": [
15
- "dist"
21
+ "dist",
22
+ "README.md"
16
23
  ],
17
24
  "engines": {
18
25
  "node": ">=18"
@@ -28,7 +35,6 @@
28
35
  "typescript",
29
36
  "auth"
30
37
  ],
31
- "license": "MIT",
32
38
  "peerDependencies": {
33
39
  "express": "^5.0.0",
34
40
  "mongoose": "^8.0.0"