This repository contains a full-stack authentication project with a React-based frontend and an Express.js-based backend. The project is designed to demonstrate user authentication using JWT (JSON Web Tokens), React Router, and secure API endpoints.
The project is divided into two main directories:
-
Framework: React
-
Features:
- React Router for client-side routing
- TailwindCSS for styling
- TypeScript for type safety
- Hot Module Replacement (HMR) for development
- Docker support for containerized deployment
-
Key Files:
app/routes/: Contains React Router route components (e.g.,home.tsx,login.tsx,dashboard.tsx).vite.config.ts: Configuration for Vite bundler.Dockerfile: Docker configuration for building and running the frontend..env: Environment variables for secure configuration.
-
Framework: Express.js
-
Features:
- JWT-based authentication
- Secure API endpoints
- Middleware for CORS and cookie parsing
- Environment variable support via
dotenv - Docker support for containerized deployment
-
Key Files:
server.js: Main server file with API routes for authentication and protected endpoints..env: Environment variables for secrets likeACCESS_TOKEN_SECRETandREFRESH_TOKEN_SECRET.Dockerfile: Docker configuration for building and running the backend.
- 🔒 Authentication: Secure user authentication using JWT.
- 🚀 Frontend: React with React Router and TailwindCSS for a modern UI.
- ⚡ Backend: Express.js for API endpoints and middleware.
- 📦 Dockerized: Both frontend and backend are containerized for easy deployment.
- 🔄 Hot Reloading: HMR for frontend development.
- 📖 TypeScript: Type-safe development for both frontend and backend.
- Node.js (v18 or higher)
- pnpm (for package management)
- Docker (optional, for containerized deployment)
-
Clone the repository:
git clone https://github.com/your-repo/fullstack-authentication.git cd fullstack-authentication -
Install dependencies for both frontend and backend:
cd authentication pnpm install cd ../server pnpm install
-
Navigate to the
authentication/directory:cd authentication -
Start the development server:
pnpm run dev
-
Open your browser at
http://localhost:5173.
-
Navigate to the
server/directory:cd server -
Start the server:
pnpm run dev
-
The backend will run at
http://localhost:3000.
-
Navigate to the
authentication/directory:cd authentication -
Build the production assets:
pnpm run build
-
The build output will be in the
build/directory.
-
Navigate to the
server/directory:cd server -
Start the production server:
pnpm run prod
-
Build and run the frontend:
cd authentication docker build -t frontend . docker run -p 5173:5173 frontend
-
Build and run the backend:
cd server docker build -t backend . docker run -p 3000:3000 backend
The containerized application can be deployed to any platform that supports Docker, including:
- AWS ECS
- Google Cloud Run
- Azure Container Apps
- Digital Ocean App Platform
- Fly.io
- Railway
ACCESS_TOKEN_SECRET: Secret for signing access tokens.REFRESH_TOKEN_SECRET: Secret for signing refresh tokens.
ACCESS_TOKEN_SECRET: Secret for verifying access tokens.REFRESH_TOKEN_SECRET: Secret for verifying refresh tokens.
POST /api/signin: Authenticate a user and return a JWT.
GET /api/protected: Access protected data (requires a valid JWT).
The frontend uses TailwindCSS for styling. You can customize the styles in the tailwind.config.js file.
This project is licensed under the MIT License.
Built with ❤️ using React and Express.js.