JWT Authentication Monorepo 🚀
A fun, full-stack todo app to master JWT authentication!
This monorepo uses npm workspaces to manage a React (TypeScript) frontend and an Express (JavaScript) backend . Perfect for learning how to implement JWT (JSON Web Token) authentication in a real-world app.
jwt-auth-monorepo/
├── package.json # 🏠 Root package.json (workspaces config)
├── client/ # 🎨 React + TypeScript frontend
│ ├── package.json
│ ├── src/
│ └── ...
├── api/ # 🖥 Express + JavaScript backend
│ ├── package.json
│ ├── src/
│ └── ...
└── README.md # 📖 You're here!
Node.js (v20 or later)
npm (v10 or later)
Basic knowledge of React , Express , and JWT
Clone the repository:
git clone https://github.com/HarenaFiantso/jwt-auth-monorepo
cd jwt-auth-monorepo
Install dependencies:
npm install # Installs everything for both client and API!
Set up environment variables:
Create .env files in both client/ and api/ directories. See Environment Variables for details.
Start the development servers:
npm run dev # 🚀 Launches both client and server in dev mode!
🎨 Client (React + TypeScript)
Location: ./client
Tech Stack: React, TypeScript, Axios, React Router
Features:
User registration and login
Todo CRUD operations
JWT storage and authentication
Protected routes
react
react-dom
axios
react-router
Script
Description
start
Start the React development server
build
Build the React app for production
dev
Start the development server
🖥 Server (Express + JavaScript)
Location: ./api
Tech Stack: Express, JSONWebToken, bcrypt, Prisma + SQLite
Features:
User registration and login endpoints
JWT generation and validation
Todo CRUD endpoints
Middleware for protected routes
express
jsonwebtoken
bcrypt
prisma
cors
dotenv
Script
Description
start
Start the Express server
dev
Start the server with nodemon
🔐 JWT Authentication Flow
User Registration:
User registers with email and password.
Password is hashed and stored in the database.
User Login:
User logs in with email and password.
Server validates credentials and generates a JWT .
JWT is sent to the client and stored (e.g., in localStorage or cookies).
Protected Routes:
Client includes the JWT in the Authorization header for protected requests.
Server validates the JWT and grants access to protected resources.
Logout:
Client removes the JWT from storage.
VITE_API_URL = http://our-api-url.com
PORT = choose_your_port
JWT_SECRET = this_need_to_be_a_secret
DATABASE_URL = the_url_database
Script
Description
npm install
Install dependencies for all workspaces
npm run dev
Start both client and server in dev mode
npm run dev:server
Start server in dev mode
npm run dev:client
Start client in dev mode
This project is licensed under the MIT License .