Skip to content

amneshpal/React-Node.js-MySQL-Authentication-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” React Node.js MySQL Authentication App

A full-stack authentication project built with:

  • Frontend: React (Vite) + Tailwind CSS
  • Backend: Node.js + Express
  • Database: MySQL
  • Authentication: JWT (JSON Web Token)

πŸ“ Project Structure

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

βš™οΈ Setup Instructions

1. πŸ“¦ Backend Setup

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


βœ… How to Use:

  1. Save this as a file: README.md in your root directory.
  2. Run:
git add README.md
git commit -m "Added complete project README"
git push

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published