JWT-Authentication Tailwind Templates

Jwt Authentication

Login/Register With JWT, MongoDB Database, Tailwind CSS

MERN Authentication System

A complete authentication system built with the MERN stack featuring JWT authentication and role-based authorization.

✨ Features

  • šŸ” User Authentication:

    • Login with email/password
    • Registration with role selection
    • JWT token-based auth
    • Password hashing with bcrypt
  • šŸ‘„ Role-Based Access:

    • Two roles: user and admin
    • Protected routes by role
    • Separate dashboards
  • šŸŽØ Frontend:

    • Responsive Tailwind CSS design
    • Form validation
    • Error handling
    • Dynamic navigation

šŸ›  Technologies

Backend

Technology Purpose
Node.js Runtime
Express.js Framework
MongoDB Database
Mongoose ODM
JWT Authentication
Bcrypt.js Password hashing

Frontend

Technology Purpose
React UI Library
React Router Routing
Tailwind CSS Styling
Heroicons Icons
Axios HTTP Client
Context API State Management

šŸ“ Project Structure

mern-auth/
ā”œā”€ā”€ backend/
│   ā”œā”€ā”€ config/       # Config files
│   ā”œā”€ā”€ controllers/  # Route controllers
│   ā”œā”€ā”€ middleware/   # Auth middleware
│   ā”œā”€ā”€ models/       # MongoDB models
│   ā”œā”€ā”€ routes/       # API endpoints
│   ā”œā”€ā”€ utils/        # Utilities
│   ā”œā”€ā”€ app.js        # Express app
│   └── server.js     # Server entry
│
ā”œā”€ā”€ frontend/
│   ā”œā”€ā”€ public/       # Static files
│   ā”œā”€ā”€ src/
│   │   ā”œā”€ā”€ components/ # UI components
│   │   ā”œā”€ā”€ context/    # Auth context
│   │   ā”œā”€ā”€ pages/      # View pages
│   │   └── ...         # Other frontend files
│   └── package.json
│
└── README.md

Clone the Repository

git clone https://github.com/adisavaliya15/JWT-Authentication.git
cd JWT-Authentication

Install Dependencies

.env File Setup:

  • MONGODB_URI=your_mongodb_connection_string
  • JWT_SECRET=your_jwt_signing_secret
  • JWT_EXPIRES_IN=token_expiry_time
  • PORT=server_port

Backend Setup:

  • cd backend
  • npm install
  • npm start

Frontend Setup:

  • cd frontend
  • npm install
  • npm start

Top categories

Loading Svelte Themes