auth-backend

Auth Backend

Typescript RESTful backend application template for User Authentication and Authorization.

👉 STAR ⭐ this project for later use and to keep posted on the changes.

Table of Contents

General Information

Features

Technologies and Techniques

Project configuration

``` 📦src ┣ 📂api => Main source code container. ┃ ┣ 📂controllers => Orchestrators that use Services and Middlewares to provide a response. ┃ ┣ 📂interfaces => Typescript Interface and Type definitions to be used in the project. ┃ ┣ 📂middlewares => Functions to be executed before the Router's main controllers. ┃ ┣ 📂models => Entity definitions that encapsulate Database and ORM apis. ┃ ┣ 📂routers => Routers of the application. ┃ ┃ ┗📂__tests__ => Jest test files. ┃ ┣ 📂services => Functions containing the all the Business Logic of the application. ┃ ┗ 📂util => Functions used multiple times across the folders in the project. ┣ 📂config => Configuration for the different components of the application. ┃ ┗ 📂tests => Test configuration files. ┣ 📂public => Publicly available resources. ┗ 📜index.ts => Main file that starts the database and the main application. ```

Main application

Security

Testing

tests-results

Setup

  1. Clone this project by doing:
    $ git clone https://github.com/pieroguerrero/auth-backend.git
    
  2. Go to the folder you’ve just cloned the code and execute:
    $ npm install
    

    WARNING: If you are going to use other libraries to achieve other purposes be carefull and remove the caret (^) prefix that the dependency versions have.

  3. Create a .env file in your project’s container folder. The file should have the following variables with your own values: ``` #Node Enviromental variable used for performance purposes NODE_ENV=”development”

#APP/SERVER CONFIGS

#Port number to be used by the current application: PORT=”3000”

#DATABASE CONFIGS

#MongoDB full connection string: MONGODB_URI=”"

#JWT TOKEN CONFIGS

#A value to be used as seed by the JWT jsonwebtoken library in order to sign the payload: SECRET_TOKEN_KEY=”" #Number of iterations for the encryption algotithm: TOKE_SALT_LENGTH=10 #JWT token expiration time, expressed in seconds or a string describing a time span zeit/ms. Eg: 60, "2 days", "10h", "7d": JWT_EXPIRATION_IN_SECONDS="" #When 'true', it will provide and receive the authorization token via the cookies. Otherwhise will handle it via Authorization header with a bearer token: TOKEN_FROM_COOKIE="false" #Useful only when TOKEN_FROM_COOKIE is 'true'. This parameter gives a name to the cookie is going to be used to provide and receive the authorization token: JWT_TOKEN_COOKIE_NAME=""

#EMAIL CONFIGS

#Gmail Email host, commonly: ‘smtp.gmail.com’: EMAIL_GMAIL_HOST=”smtp.gmail.com” #Gmail email address to use used as the email sender: EMAIL_GMAIL_ADDRESS=”" #Gmail email sender password: EMAIL_GMAIL_PASS="" #Secret key to perform Email Verification testing with Jest and Supertest. You can get one free at: https://mailslurp.com/ EMAIL_MAILSLURP_KEY="YOUR KEY HERE"

#API SECURE SETTINGS #Establishes the time in milliseconds in wich an IP can make a certain number of calls RATE_LIMIT_TIME_IN_MS=”60000” #Establishes the number of calls that can be made in the time set by RATE_LIMIT_TIME_IN_MS RATE_LIMIT_MAX_CALLS=”2” #How long to keep records of requests in memory. SPEED_LIMIT_TIME_WINDOW_IN_MS=”30000” #Max number of connections during SPEED_LIMIT_TIME_WINDOW_IN_MS before starting to delay responses. Defaults to 1. Set to 0 to disable delaying. SPEED_LIMIT_DELAY_AFTER=”1” #How long to delay the response, multiplied by (number recent hits - SPEED_LIMIT_DELAY_AFTER). Defaults to 1000 (1 second). Set to 0 to disable delaying. SPEE_LIMIT_DELAYING_TIME_IN_MS=”500”

```

Project Status

Project is: in progress

Room for Improvement

There are always room for improvement, in this project so far the thinkgs that can be improved are: