Code Monkey home page Code Monkey logo

jwt-auth's Introduction

Boilerplate

TypeScript, TypeORM, JWT - API Boilerplate.

Index

๐Ÿ”– About

This is a Boilerplate to start quick and fresh your new project with authentication and authorization using JWT, TypeORM and TypeScript. This project was made by Matheus Silva - Youtube.

๐Ÿ”ฅ Functionalities

  • Register

    • Register User with: Name, Email and Password.
    • On Register: check if user alreay exists (unique email).
    • On Register: check if user added name, email and password.
    • Hash user password using bcryptjs.
  • Authenticate

    • Authenticate user with Email and Password.
    • On authenticate: check if user added name and password.
    • On authenticate: check if user is valid.
    • On authenticate: check if password matches with hash.
    • Receive token as response containing: id, name, email, user type (admin / user).
  • Middleware

    • Middleware check if has a token and if is valid.

๐Ÿš€ Technologies

The project is made with:

๐Ÿ”ฅ How to Use

  • Dependencies

    • Is required to install Node.js
    • In order to run scripts and install dependencies you need to install a package manager (ie: YARN).

  1. First step, clone this github repository:
  $ git clone https://github.com/dpisati/node-typeorm.git
  1. Add variables on .env file:

The api requires some environment variables stored inside the .env file.

Example:

File: .env

Content:

PORT = add a port or run on 3333 by default
JWT_SECRET = strong password to be used by JWT
JWT_EXPIRES_IN = set how long the token should be valid
  1. Configure ormconfig.json to connect the database. Default values as below:
{
    "type": "mysql",
    "host": "localhost",
    "port": 3306,
    "username": "root",
    "password": "",
    "database": "node-typeorm",
    "entities": [
       "src/app/models/*.ts"
    ],
    "migrations": [
       "src/database/migrations/*.ts"
    ],
    "cli": {
        "migrationsDir": "src/database/migrations"
    }
 }
  1. Run the application:
  # Install dependencies.
  $ yarn install

  ## Create the database using TypeORM
  $ yarn typeorm migration:run

  # Start the API
  $ yarn run dev

โ™ป๏ธ How to Contribute

  • Create a Fork from this repo,
  • Create a branch with your feature: git checkout -b my-feature
  • Commit changes: git commit -m 'feat: My new feature'
  • Push to your branch: git push origin my-feature

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.