NestJS JWT authentication service using NestJS, Docker and MySQL. It can be used as a JWT Auth Microservice or can be used as starter repository for an API project.
- 
Pre-Requisite - For dockerized environment we need
- docker,
- docker-composeinstalled.
 
- To run API server without Docker we need
- Node.js(>= 10.13.0) installed,
- Dependency manager yarninstalled,
- Nestjs CLI nestinstalled (follow here) and
- MySQL server running
 
 
- For dockerized environment we need
- 
Configuration - In application root, create .envcopying form example env fileenv.example.
- An example env file contains
- MySQL credentials for the dockerized environment. For non-docker setup, update MySQL credentials here.
- Password encription salt and JWT secret key values. Change them with some secret values.
 
 
- In application root, create 
- 
Run API - For Docker: Up docker-compose, this will create a docker container with the database with the given name in env.
 $ docker-compose up --build- For non-docker run install dependencies and run nodejs API server
 $ yarn $ yarn run start
- 
API Documentation - To get API documentation run following command & browse at http://127.0.0.1:8089/
 $ yarn run start:api-doc
- 
API With above steps done, API should be up and running - Browse APIat http://localhost:3000
- Browse Swagger Open APIDoc at http://localhost:3000/api
- Browse (for Docker only) DB Adminerat http://localhost:8080
 
- Browse 
- TypeORM CLIused to manage DB migration. ORM configurations are available in the- orm.config.tsfile.
- Migration auto-synchronization is set to trueindevelopmentenvironment, andfalsein other environments.
- To create a new empty migration file, use migration:createcommand.
$ yarn migration:create -n createUsers
- TypeORM can generate a migration file from changed entity files comparing with the database. To generate a populated migration file from entity files, use migration:generatecommand
$ yarn migration:generate -n createUsers
- To run DB migration:
$ yarn migration:run
- To rollback migration:
$ yarn migration:revert
Read more about TypeORM migration [here][https://typeorm.io/#/migrations]
yarn test or npm run test
Feel free to submit issues or PRs. You can checkout the coding style guide before submitting the PRs. Link is here.
- Author - S M Asad Rahman
- Twitter - @asad_rahman