This project is about a web application with a robust authentication system built using React for the frontend, Express.js for the backend, and MySQL as the database. User interaction with the backend is handled via cookies for authentication and session management.
The application is divided into three main components:
- API: Handles the backend logic and database interactions.
- Client: The user-facing frontend application.
- Admin: A separate administration interface for managing the application.
- User authentication system (login, signup, logout).
- Role-based access control for regular users and administrators.
- Secure connection to a MySQL database.
- Intuitive user interface built with React.
- Admin panel for managing users and application data.
- Email verification system: Sends a confirmation email upon user registration.
- Password reset functionality: Sends a reset link via email to users who forgot their password.
To run this project, ensure you have the following installed:
Before starting, ensure that your MySQL server is installed, running, and properly configured.
- Open your MySQL client or a database tool like MySQL Workbench, phpmyadmin etc.
- Run the command to create a database named
ReactFullAuth
.
- The necessary database tables are defined in the
/api/schema.sql
file. - Import this file into your database or execute its contents manually.
Now your MySQL database is ready for use!
-
To send emails (such as verification and password reset emails), you need to set up your own SMTP server.
-
You can use Gmail SMTP easily with your Google account.
-
Update your
.env
file with the following SMTP details:- SMTP_HOST: Your SMTP server (e.g.,
smtp.gmail.com
for Gmail). - SMTP_PORT:
587
for TLS,465
for SSL,25
for non-secure connections. - SMTP_SECURE: Set to
true
for secure connections. - SMTP_MAIL: Your email address (e.g.,
your-email@gmail.com
). - SMTP_PASSWORD: Your email password or an App Password for security.
- SMTP_HOST: Your SMTP server (e.g.,
-
If using Gmail, enable "Less Secure Apps" (if necessary) or generate an App Password from your Google Account security settings.
git clone https://github.com/Klajdis32/Express.js-React-MySQL-Authentication-System.git
cd <repository_folder>
- Navigate to the API folder:
cd api
- Install dependencies:
npm install
- Start the API server:
npm start
- Navigate to the Client folder:
cd ../client
- Install dependencies:
npm install
- Start the Client interface:
npm start
- Navigate to the Admin folder:
cd ../admin
- Install dependencies:
npm install
- Start the Admin interface:
npm start
<project-folder>
|
├── api/ # Backend API built with Express.js
├── admin/ # Admin panel frontend
└── client/ # Client-facing frontend
- API: Serves as the central hub connecting the frontend applications to the database.
- Client: Allows users to interact with the application (e.g., login, view content).
- Admin: Provides tools for administrators to manage users and data.
- Ensure all necessary environment variables (e.g., database credentials, JWT secret) are set before running the application.
- The application runs on default ports (API:
http://localhost:8081
, Admin:http://localhost:3001
, Client:http://localhost:3000
). Adjust these if needed.