Day 1: Setup Project -
✅ Goal → Create base project and server.
Install dependencies:
npm init -y npm install express mongoose bcryptjs jsonwebtoken
Create index.js with Express.
Connect MongoDB with Mongoose.
Day 2: User Model
✅ Goal → Define how user data will be stored.
Create models/User.js with username and password.
Ensure username is unique.
Test with dummy data (create a new user manually).
Day 3: Register Route (Signup)
✅ Goal → New users can register.
Create routes/auth.js.
Add /register route.
Hash password using bcrypt before saving.
Save user to DB.
Day 4: Login Route
✅ Goal → Allow users to login.
Add /login route.
Check username + compare password with bcrypt.
Generate JWT token with jsonwebtoken.
Return token in response.
Day 5: Middleware for Protected Routes
✅ Goal → Secure some routes.
Create authMiddleware.js.
Verify token using jwt.verify.
Add /dashboard route that only works with valid token.
Day 6: Improve Security & Structure
✅ Goal → Make code production-friendly.
Store secretkey in .env using dotenv.
Split routes, models, and controllers into folders.
Add error handling.
Day 7: Advanced Add-ons (Optional)
✅ Goal → Go beyond basics.
Add Logout (just delete token client-side).
Add Role-based Auth (admin vs user).
Try Refresh tokens.