Skip to content

A comprehensive user authentication system in Node.js. It provides a robust and secure way to handle user registration, login, and authentication using modern practices and technologies.

License

Notifications You must be signed in to change notification settings

carpodok/user-auth-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

User Authentication System

Frame 5

Overview

This project is an implementation of a user authentication system in Node.js. It provides a robust and secure way to handle user registration, login, and authentication using modern practices and technologies.

Features

  • User Registration: Allows new users to create an account with their email and password.
  • User Login: Authenticates users with their email and password.
  • Password Hashing: Uses bcrypt to hash passwords for security.
  • JWT Authentication: Issues JSON Web Tokens (JWT) for authenticated sessions.
  • Middleware Protection: Protects routes by verifying JWT tokens.
  • Cookies Usage: Stores JWT in HTTP-only cookies on the client side for secure session management.

Technologies Used

  • Node.js: Backend runtime environment.
  • Express.js: Web framework for Node.js.
  • MongoDB: NoSQL database for storing user data.
  • Mongoose: ODM for MongoDB.
  • Bcrypt: Library for hashing passwords.
  • JSON Web Tokens (JWT): Standard for creating secure access tokens.
  • React.js: Frontend library for building user interfaces.
  • js-cookie: JavaScript library for handling cookies on the client side.

Installation

  1. Clone the repository
git clone https://github.com/carpodok/user-auth-system.git
  1. Navigate to the project directory:
 cd authentication-system
  1. Install dependencies for both server and client:
cd server
npm install
cd ../client
npm install

Configuration

  1. Creat a .env file in the server directory and add the following environment variables
PORT=3000
MONGODB_URI=your_mongodb_uri
JWT_SECRET=your_jwt_secret

Running the Application

  1. Start the server:
cd server
npm start
  1. Start the client:
cd client
npm start
  1. The application will be running on http://localhost:3000 for the server and http://localhost:3001 for the client.`

Client Side Details

login_page

register_page

The client side of this project is built using React.js to provide a seamless user experience. Here are some key components and their functionalities:

  • Register: A form to register a new user. It collects the user's email and password and sends a POST request to the /api/register endpoint.
  • Login: A form to authenticate an existing user. It collects the user's email and password and sends a POST request to the /api/login endpoint.
  • ProtectedRoute: A component that checks for a valid JWT token before allowing access to protected routes.
  • Wellcome: A sample protected component that is only accessible to authenticated users.

Key files and Directories

client/
├── public/
├── src/
│   ├── components/
│   │   ├── Register.js
│   │   ├── Login.js
│   │   ├── ProtectedRoute.js
│   │   ├── Welcome.js
│   ├── services/
│   │   ├── authService.js
│   ├── App.js
│   ├── index.js
├── package.json

Server Side Details

The server side of this project is built using Node.js and Express.js to handle backend operations. Here are some key components and their functionalities:

  • authController.js: Contains the logic for handling user registration, login, and issuing JWTs.
  • authMiddleware.js: Middleware for protecting routes by verifying JWT tokens.
  • User.js: Mongoose model for storing user data in MongoDB.
  • authRoutes.js: Defines the routes for user registration, login, and protected routes.
  • db.js: Configures the connection to the MongoDB database.

Key Files and Directories

server/
├── src/
│   ├── config/
│   │   ├── db.js
│   ├── controllers/
│   │   ├── authController.js
│   ├── middleware/
│   │   ├── authMiddleware.js
│   ├── models/
│   │   ├── User.js
│   ├── routes/
│   │   ├── authRoutes.js
│   ├── server.js
├── .env
├── package.json

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or suggestions.

License

This project is licensed under the MIT License.

About

A comprehensive user authentication system in Node.js. It provides a robust and secure way to handle user registration, login, and authentication using modern practices and technologies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published