Skip to content

m0nkeyh4ck/auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJS Auth REST API example with Express, Mysql, and JWT

Features

  1. User can sign up
  2. User can sign in

API endpoints

  1. POST /api/auth/signup: Creates a new user
  2. POST /api/auth/signin: Logs in a user

Body Payload Specification

Signup expects

POST /api/auth/signup HTTP/1.1
Host: localhost:3000
Content-Type: application/json
Content-Length: 125

{
    "username": "chucho",
    "email": "usud@effmplo.com",
    "password": "Mitigado123"  
}

Signin expects

POST /api/auth/signin HTTP/1.1
Host: localhost:3000
Content-Type: application/json
Content-Length: 71

{
    "username": "pepitoperres",
    "password": "Mitigado123"
}

Tools

  • NodeJS/Express: Server
  • MySQL: Storage
  • JWT: Token based authentication
  • bcryptjs: Password security
  • winston/morgan: Logs
  • Joi: Validations

Available scripts

  • start: Starts the server with node
  • start:dev: Starts the server in watch mode
  • db:up: Creates the database
  • db:down: Drops the database
  • tables:up: Creates database tables
  • db:init: Creates both the database and tables

Getting started

You can either fork this repository or clone it by starting your terminal, then change the directory to where you would like to save it and run

git clone https://github.com/desirekaleba/node-mysql-jwt-auth.git

Change to the newly downloaded directory with

cd node-mysql-jwt-auth

Rename the file named .env.example to .env and update the variable values with valid ones

Install the required dependencies with

npm install

Initialize the database with

npm run db:init

Start the app with

npm start

You can also start it in watch mode with

npm run start:dev

Folder structure

.
├── README.md
├── package-lock.json
├── package.json
└── src
    ├── app.js
    ├── config
    │   ├── db.config.init.js
    │   └── db.config.js
    ├── controllers
    │   └── auth.controller.js
    ├── database
    │   ├── queries.js
    │   └── scripts
    │       ├── dbDown.js
    │       ├── dbUp.js
    │       └── tablesUp.js
    ├── index.js
    ├── middlewares
    │   ├── asyncHandler.js
    │   ├── checkEmail.js
    │   └── validatorHandler.js
    ├── models
    │   └── user.model.js
    ├── routes
    │   └── auth.route.js
    ├── utils
    │   ├── logger.js
    │   ├── password.js
    │   ├── secrets.js
    │   └── token.js
    └── validators
        └── auth.js

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published