A full-stack authentication project built with:
- Frontend: React (Vite) + Tailwind CSS
- Backend: Node.js + Express
- Database: MySQL
- Authentication: JWT (JSON Web Token)
project/
βββ backend/
β βββ routes/
β β βββ authRoutes.js
β βββ lib/
β β βββ db.js
β βββ index.js
β βββ .env
βββ frontend/
β βββ src/
β β βββ pages/
β β β βββ Login.jsx
β β β βββ Register.jsx
β β β βββ Home.jsx
β β βββ components/
β β β βββ Navbar.jsx
β β βββ App.jsx
β βββ vite.config.js
cd backend
npm install
Create a .env file in backend/:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=
DB_NAME=authentication
PORT=3000
JWT_KEY=jwt-secret-key
Start the backend server:
nodemon index.js
###2. π» Frontend Setup
cd frontend
npm install
npm run dev
##β Features π JWT-based Login & Signup
π Secure password hashing with bcrypt
π Token verification middleware
π Protected /home route (accessible only after login)
π Frontend navigation with React Router
π¨ Styled using Tailwind CSS
##π API Endpoints
Method Endpoint Description
POST /auth/register Register new user
POST /auth/login Login user & return JWT
GET /auth/home Get user info (protected)
###π MySQL Table
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255),
email VARCHAR(255) UNIQUE,
password VARCHAR(255)
);
##π‘ Token Storage After login, token is saved in localStorage:
localStorage.setItem('token', token);
Sent with protected requests:
headers: {
Authorization: `Bearer ${token}`
}
###π Future Improvements β Role-based access (Admin/User)
π¬ Forgot password via email
π± Responsive mobile design
βοΈ Form validation with Zod or Yup
###π· Preview Add screenshots/gifs of login and home page here
###π§βπ» Author Amnesh Pal π Sector 44, Gurgaon π§ amneshpal15@gmail.com
- Save this as a file:
README.md
in your root directory. - Run:
git add README.md
git commit -m "Added complete project README"
git push