Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/navaneeth-21/auth_system-mysql-

This is an Authentication System for Login and Register Routes which uses json web tokens for authorization .The Application is connected to the Mysql database to store the user details in a structured format.
https://github.com/navaneeth-21/auth_system-mysql-

expressjs jest jwt mysql rest-api

Last synced: about 1 month ago
JSON representation

This is an Authentication System for Login and Register Routes which uses json web tokens for authorization .The Application is connected to the Mysql database to store the user details in a structured format.

Awesome Lists containing this project

README

        

# Auth System with mysql
A Basic Authentication System with user registration and login functionalities using Node.js , Express and Mysql .
This project uses JWT for authenticating the users using tokens

## Features
- It consists of following RESTful endpoints :
- POST /register: Register a new user.
- POST /login: Login a user and return a JWT.
- GET /profile: Retrieve the logged-in user's profile information (protected endpoint).

## Technologies used

- **Backend:** Express.js , MYSQL , JWT , RESTAPI
- **Testing:** Jest,supertest

## Getting Started

### Prerequisites

- Node.js and npm installed
- Install MYSQL or MYSQL workbench and create a user

### Installation

1. clone the repository
2. Install all dependencies.
3. Create a .env file and enter the following details :
- jwt_secret_key
- user
- host
- password
- Database name
4. Run the following SQL commands to set up the database and users table.
5. Start the application

npm start

6. Run the following endpoints in postman or any other api requests extensions
- Register :

POST -H "Content-Type: application/json" -d '{"username":"testuser","password":"testpass"}' http://localhost:3000/api/auth/register

- Login :

POST -H "Content-Type: application/json" -d '{"username":"testuser","password":"testpass"}' http://localhost:3000/api/auth/login

- Access protected route:

-H "Authorization": Bearer http://localhost:3000/api/auth/protected

## Testing
Unit tests are written using jest. To run tests :

npm test