β Click the link below to access the live application and navigate to the Sign Up page.
β Use your Real Email Address and Any Password to register (passwords are securely hashed).
β You will receive Verification Email and other System Emails, follow the steps provided in the email.
π Try the Advanced MERN Authentication System:
https://advanced-mern-auth-app-s552q.ondigitalocean.app
β οΈ Note: Sometimes, emails may be delivered to your Spam or Promotions folder. If you donβt see any emails in your inbox, please check those folders.
A full-stack, production-ready MERN (MongoDB, Express, React, Node.js) authentication system that supports secure user registration, email verification, password recovery, and session management. Built with a scalable architecture and containerized using Docker, it integrates Mailtrap and Brevo email services for real-time email delivery and is deployed on DigitalOcean for seamless cloud accessibility.
- π JWT Authentication with HTTP-only Cookies.
- π¨ Email Verification via 6-Digit Code (Development: Mailtrap, Production: Brevo).
- π© Welcome Emails sent after successful verification.
- π Forgot & Reset Password flow with secure token-based links.
- β Password Strength Validation.
- π§ Authentication Check API to validate active user sessions.
- π Sign-Out by clearing the authentication cookie.
The following technologies are used in this project:
Technology | Description |
---|---|
Node.js | JavaScript runtime for server-side development |
Express.js | Minimalist web framework for Node.js |
MongoDB + Mongoose | NoSQL database with object modeling tool |
JWT | Used for stateless session authentication |
BcryptJS | Library for securely hashing passwords |
Brevo | Email API service for production email delivery |
Mailtrap | Email testing service for development environment |
Cookie Parser | Middleware to parse HTTP cookies |
Crypto | Built-in encryption utilities |
CORS | Cross-origin resource sharing support |
------------------------ | ----------------------------------------------------------------------------- |
React 19 | UI library for interactive interfaces |
React Router v7 | Routing library for single-page React apps |
TailwindCSS | Utility-first CSS framework for styling |
Axios | Promise-based HTTP client for API requests |
Framer Motion | Animation library for React components |
Zustand | Lightweight global state management tool |
Lucide-react | Icon library for modern, customizable icons |
Vite | Fast frontend build tool and dev server |
The following project structure (client-server architecture) is used in this project:
advanced-mern-auth-system/
βββ client/ # Frontend (React + Vite)
β βββ dist/ # Production build output
β βββ node_modules/ # Frontend dependencies
β βββ public/ # Static assets
β βββ src/ # Source code for the React app
β β βββ components/ # Reusable UI components (Inputs, etc.)
β β βββ pages/ # Page-level components (Login, Signup, etc.)
β β βββ store/ # Zustand global state management
β β βββ utils/ # Utility functions (e.g., date handling)
β β βββ App.jsx # Main app structure and route definitions
β β βββ main.jsx # React root renderer
β β βββ index.css
β βββ index.html
β βββ vite.config.js
β βββ tailwind.config.js # Tailwind CSS configuration
β βββ postcss.config.js
β βββ eslint.config.js
β βββ package.json # Frontend dependencies and scripts
β βββ package-lock.json
βββ node_modules/ # Root-level dependencies (backend)
βββ server/ # Backend (Node.js + Express)
β βββ controllers/ # Route handler logic (e.g., auth, user)
β βββ db/ # MongoDB connection logic
β βββ mailtrap_brevo/ # Email services (Mailtrap for dev, Brevo for prod)
β βββ middleware/ # Middleware (e.g., verifyToken)
β βββ models/ # Mongoose schema definitions
β βββ routes/ # Express route definitions
β βββ utils/ # Utility functions (e.g., token generation)
β βββ server.js # Express server entry point
βββ .dockerignore # Files to ignore in Docker build
βββ .env # Environment variables for the backend
βββ .gitignore # Git ignored files
βββ Dockerfile # Docker configuration for full app deployment
βββ LICENSE
βββ package.json # Backend dependencies and scripts
βββ package-lock.json
βββ README.md # Project documentation
Follow the steps below to set up and run the project successfully:
git clone https://github.com/PAIshanMadusha/advanced-mern-auth-system.git
cd advanced-mern-auth-system
Create a .env
file in the root directory of the project using the structure below:
MONGODB_URL=your_mongo_db_connection_string
PORT=5000
JWT_SECRET=your_jwt_secret
CLIENT_URL=http://localhost:5000
NODE_ENV=production
MAILTRAP_TOKEN=your_mailtrap_token
MAILTRAP_ENDPOINT=https://send.api.mailtrap.io/
BREVO_API_KEY=your_brevo_api_key
BREVO_SENDER_EMAIL=your_sender_email
BREVO_SENDER_NAME=your_sender_name
MONGODB_URL
* Your MongoDB connection string. Create a free cluster using MongoDB Atlas, then copy the connection URI and paste it here.
PORT
JWT_SECRET
* A secret key used to sign and verify JWT tokens. You can generate a secure random value by running the following command in your terminal:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
CLIENT_URL
* The base URL of your frontend application: In development: http://localhost:5173
, In production or Docker setups: http://localhost:5000
NODE_ENV
* Defines the environment mode. Use: development
during local development and production
when deploying to production
MAILTRAP_TOKEN
* API token used to send test emails via Mailtrap: Log in or sign up at Mailtrap.io, then navigate to: Email API β Demo Inbox β Integrations** to find your token.
MAILTRAP_ENDPOINT
https://send.api.mailtrap.io/
BREVO_API_KEY
* Your Brevo (formerly Sendinblue) API key for sending real production emails, and generate it from SMTP & API under your Brevo Dashboard.
BREVO_SENDER_EMAIL
* A verified sender email used to send emails via Brevo in production, and set this from Senders, Domains & Dedicated IPs β Add Sender in your Brevo account.
BREVO_SENDER_NAME
* The name that appears in the "From Name" field when sending emails, and this can be your app name, personal name, or business name. Configure it along with the sender email in Brevo.
npm run build
npm start
Server is running on port: 5000
MongoDB Connected: your-cluster.mongodb.net
* Visit: http://localhost:5000, and test the app in production mode using your registered credentials.
To run the project in development mode:
NODE_ENV=development
CLIENT_URL=http://localhost:5173
* Also, make sure to accurately set the Mailtrap keys (MAILTRAP_TOKEN
, MAILTRAP_ENDPOINT
) in the same .env
file.
cd advanced-mern-auth-system/server
npm run dev
cd advanced-mern-auth-system/client
npm run dev
http://localhost:5173/
Server is running on port: 5000
MongoDB Connected: your-cluster.mongodb.net
* Visit: http://localhost:5173, and test the app in development mode using your registered credentials.
This application is fully containerized using Docker with multi-stage builds for both the client
and server
. It can be deployed on DigitalOcean or any platform that supports Docker containers, using GitHub integration and environment-specific .env
secrets for production.
* If not installed, download it from Docker Official Site and, docker must be configured to use Linux containers.
docker build -t advanced-mern-auth .
docker run --env-file .env -p 5000:5000 advanced-mern-auth
Server is running on port: 5000
MongoDB Connected: your-cluster.mongodb.net
* Open your browser and go to: π http://localhost:5000
These screenshots illustrate how the system appears on desktop:
Ishan Madhusha
GitHub: PAIshanMadusha
Feel free to explore my work and get in touch if you'd like to collaborate! π
This project is licensed under the MIT License : See the LICENSE file for details.