Giter VIP home page Giter VIP logo

koa-api's Introduction

koa API

KoaJS backend has a fleshed-out user login, signup, forgot password, email verification, with refresh token using JWT, includes example seed data for users.

Technologies

  • Koa 2.13.0
  • Fully written using async/await & Classes
  • Koa-Router
  • Koa-Body-parser
  • KCors
  • Koa-Json-Error for JSON requests/responses
  • Bcrypt
  • Sendgrid for emails
  • Nodemon for running in development
  • Babel
  • Use PM2 to run on production
  • MongoDB with Mongoose (mongoose validation)
  • Seed users data for testing app
  • Password recover system with token
  • Authentication with JWT token and refreshToken stored in secure cookies

Installing / Getting started

  • Important! rename example.env to .env and enter your credentials & make sure you have mongoDB running.
  • Create certs & keys directories inside the secrets directory and generate local certs and key inside. Secure cookie are used on local development (to simulate production issue).
# Install dependencies
npm i

# Development with nodemon with hot reload
npm start

# Builds for production with prettier (formats the code), babel (ES5 conpatible) and createss a build directory.
npm run build

# Run the following in production using pm2
npm run live

# Formats the code for readability using prettier
npm run format

# Runs tests TODO
npm run test

# TODO need to refactor. But for now add type: module on the package.json before you run the following to seed users
# for testing the app. !important it will rewrite MongoDB data & remove type: module from package.json after.
npm run seed

General Information

User Authentication Process

User authentication process:

  • User creates an account
  • User verifies the email
  • User logs in
  • The server sets both token and refreshToken on a secure cookie
  • We take the token and decode it using jwt-decode. This gets us the logged-in user's information
  • If the token expires and the refreshToken is still valid we issue a new token.

PM2

Yep, PM2 is awesome on production.

The src folder is the heart of the program.

Controllers

We use controllers to keep our router thin.

The controller's responsibility is to manage the request body and make sure it's nice and clean when it eventually

gets sent to a model to make database calls.

db

MongoDB with Mongoose for speed and fairly easy to used.

middleware

The custom middleware we're using is based on the koa-jwt library.

models

Our models folder where database calls are made and validation is performed

routes

This is where we do authentication for restricted URL

index.js

index.js it's the brain of the app.

License

copyright 2001 Oscar Quinteros

MIT

koa-api's People

Contributors

mylastore avatar

Stargazers

Syed Arslan Haider avatar

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.