Skip to content

A full-stack authentication system built with React (Vite) on the frontend and Node.js, Express, MongoDB on the backend. It includes user registration, login, logout, email verification via OTP, and password reset via OTP — all secured with HTTP-only cookies.

License

Notifications You must be signed in to change notification settings

laxman-goud/MERN-Authentication-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔐 Authentication System

A full-stack authentication system built with React (Vite) on the frontend and Node.js, Express, MongoDB on the backend.
It includes user registration, login, logout, email verification via OTP, and password reset via OTP — all secured with HTTP-only cookies.


✨ Features

  • 🔑 User Registration & Login
  • 🔒 JWT Authentication with secure cookies
  • 🚪 Logout (clears cookies safely)
  • 📧 Email Verification (OTP sent to user’s email)
  • 🔄 Password Reset (via OTP email)
  • 🛡 Protected Routes using middleware
  • 🎨 Responsive UI with TailwindCSS
  • 🔔 Toast notifications for instant feedback

🛠 Tech Stack

Frontend (Client)

  • React (Vite)
  • React Router DOM
  • TailwindCSS
  • Axios
  • React Toastify

Backend (Server)

  • Node.js + Express
  • MongoDB + Mongoose
  • JWT (jsonwebtoken)
  • bcryptjs (password hashing)
  • Nodemailer (OTP emails)
  • cookie-parser, cors

⚙️ Installation & Setup

1️⃣ Clone the repository

git clone https://github.com/your-username/auth-system.git
cd auth-system

2️⃣ Setup Backend

cd server
npm install

Create a .env file in the server/ directory (or copy .env.example):

MONGODB_URI=your_mongodb_uri
JWT_SECRET=your_jwt_secret
NODE_ENV=development

SMTP_USER=your_smtp_user
SMTP_PASS=your_smtp_password
SENDER_EMAIL=[email protected]

Run the server:

npm run server

3️⃣ Setup Frontend

cd ../client
npm install

Create a .env file in the client/ directory (or copy .env.example):

VITE_BACKEND_URL=http://localhost:3000

Run the client:

npm run dev

📂 Project Structure

Authentication System/
│── client/                 # React frontend
│   ├── src/                # Components, Context, Pages
│   ├── public/             # Static files
│   └── README.md
│
│── server/                 # Express backend
│   ├── config/              # DB & nodemailer configs
│   ├── controllers/        # Auth & User controllers
│   ├── middleware/         # JWT middleware
│   ├── models/             # Mongoose models
│   ├── routes/             # API routes
│   ├── server.js           # Entry point
│   └── README.md
│
│── LICENSE.md
│── CONTRIBUTING.md
│── README.md               # Root project README

📜 License

This project is licensed under the MIT License.
See MIT License for details.


🤝 Contributing

Contributions are welcome! 🎉
Please check CONTRIBUTING.md for guidelines.


About

A full-stack authentication system built with React (Vite) on the frontend and Node.js, Express, MongoDB on the backend. It includes user registration, login, logout, email verification via OTP, and password reset via OTP — all secured with HTTP-only cookies.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Languages