shaonu-authkit 1.0.0 โ 1.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.
- package/README.md +133 -0
- package/bin/index.js +1 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# ๐ shaonu-authkit
|
|
2
|
+
|
|
3
|
+
A CLI tool to instantly scaffold a full **Express + MongoDB** Authentication Service.
|
|
4
|
+
|
|
5
|
+
Just one command and your auth backend is ready!
|
|
6
|
+
|
|
7
|
+
## ๐ Quick Start
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx shaonu-authkit
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## ๐ What It Does
|
|
14
|
+
|
|
15
|
+
When you run the command, it will ask you:
|
|
16
|
+
|
|
17
|
+
- ๐ Project name
|
|
18
|
+
- ๐ MongoDB URI
|
|
19
|
+
- ๐ JWT Secret
|
|
20
|
+
- ๐ Port number
|
|
21
|
+
- ๐ฆ Package manager (npm / yarn / pnpm)
|
|
22
|
+
|
|
23
|
+
Then it will:
|
|
24
|
+
|
|
25
|
+
- โ
Create your project folder
|
|
26
|
+
- โ
Create the full auth service template
|
|
27
|
+
- โ
Generate `.env` file with your values
|
|
28
|
+
- โ
Install all dependencies automatically
|
|
29
|
+
|
|
30
|
+
## ๐ก API Routes
|
|
31
|
+
|
|
32
|
+
| Method | Route | Description | Protected |
|
|
33
|
+
|--------|-------|-------------|-----------|
|
|
34
|
+
| POST | `/api/auth/register` | Register new user | โ |
|
|
35
|
+
| POST | `/api/auth/login` | Login user | โ |
|
|
36
|
+
| POST | `/api/auth/logout` | Logout user | โ
|
|
|
37
|
+
|
|
38
|
+
## ๐ Project Structure
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
your-project/
|
|
42
|
+
โโโ src/
|
|
43
|
+
โ โโโ config/
|
|
44
|
+
โ โ โโโ db.js โ MongoDB connection
|
|
45
|
+
โ โโโ controllers/
|
|
46
|
+
โ โ โโโ auth.controller.js โ Register, Login, Logout logic
|
|
47
|
+
โ โโโ models/
|
|
48
|
+
โ โ โโโ user.model.js โ User schema
|
|
49
|
+
โ โโโ routes/
|
|
50
|
+
โ โโโ auth.routes.js โ API routes
|
|
51
|
+
โ
|
|
52
|
+
โโโ app.js โ Express app entry point
|
|
53
|
+
โโโ .env โ Your environment variables
|
|
54
|
+
โโโ package.json
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## โ๏ธ Environment Variables
|
|
58
|
+
|
|
59
|
+
After setup, your `.env` file will look like:
|
|
60
|
+
|
|
61
|
+
```env
|
|
62
|
+
PORT=5000
|
|
63
|
+
MONGO_URI=mongodb://localhost:27017/authkit
|
|
64
|
+
JWT_SECRET=your-secret-key
|
|
65
|
+
JWT_EXPIRE=7d
|
|
66
|
+
NODE_ENV=development
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## ๐ฆ Dependencies Used
|
|
70
|
+
|
|
71
|
+
| Package | Purpose |
|
|
72
|
+
|---------|---------|
|
|
73
|
+
| `express` | Web framework |
|
|
74
|
+
| `mongoose` | MongoDB ODM |
|
|
75
|
+
| `bcryptjs` | Password hashing |
|
|
76
|
+
| `jsonwebtoken` | JWT tokens |
|
|
77
|
+
| `cookie-parser` | Cookie handling |
|
|
78
|
+
| `dotenv` | Environment variables |
|
|
79
|
+
| `nodemon` | Auto restart in dev |
|
|
80
|
+
|
|
81
|
+
## ๐งช Test Your API
|
|
82
|
+
|
|
83
|
+
### Register
|
|
84
|
+
```bash
|
|
85
|
+
curl -X POST http://localhost:3000/api/auth/register \
|
|
86
|
+
-H "Content-Type: application/json" \
|
|
87
|
+
-d '{"name": "John", "email": "john@example.com", "password": "123456"}'
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Login
|
|
91
|
+
```bash
|
|
92
|
+
curl -X POST http://localhost:3000/api/auth/login \
|
|
93
|
+
-H "Content-Type: application/json" \
|
|
94
|
+
-d '{"email": "john@example.com", "password": "123456"}'
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Logout
|
|
98
|
+
```bash
|
|
99
|
+
curl -X POST http://localhost:3000/api/auth/logout \
|
|
100
|
+
-H "Authorization: Bearer YOUR_TOKEN_HERE"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## ๐ Security Features
|
|
104
|
+
|
|
105
|
+
- โ
Passwords hashed with **bcryptjs** (12 salt rounds)
|
|
106
|
+
- โ
JWT stored in **httpOnly cookie** (XSS protection)
|
|
107
|
+
- โ
**sameSite: strict** cookie (CSRF protection)
|
|
108
|
+
- โ
Password never returned in API responses
|
|
109
|
+
- โ
Token invalidated on logout
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## ๐ Get Started After Setup
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
cd your-project-name
|
|
116
|
+
npm run dev
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Server runs on:
|
|
120
|
+
```
|
|
121
|
+
http://localhost:3000
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## ๐จโ๐ป Author
|
|
125
|
+
|
|
126
|
+
Made with โค๏ธ by **Shaonu**
|
|
127
|
+
|
|
128
|
+
- GitHub: [@shaonu](https://github.com/mrsaxena01)
|
|
129
|
+
- NPM: [shaonu-authkit](https://www.npmjs.com/package/shaonu-authkit)
|
|
130
|
+
|
|
131
|
+
## ๐ License
|
|
132
|
+
|
|
133
|
+
MIT License โ free to use in any project!
|
package/bin/index.js
CHANGED