Giter Site home page Giter Site logo

c001-login's Introduction

Requirements:

  • Use NestJs to create a restful-API using the db scheme and the endpoint description in the AppIndex
  • Try not to use the ORM for serialization and making the query
  • Use custom validation pipe /decorators
  • Document how to fire up the project
  • Please use a git based version control and share the repo with us
  • Use redis or any other in-memory cache technique.
  • Create docker containers for the user service with it's database. The system consists of three containers:
    • A relational database service of your choice (ex: mysql, mssql, postgres, etc...)
    • A node js service running the NestJs framework
    • A redis instance
  • Extra for a full stack position:
    • Create react app (looks are not important) using the endpoints you created in NestJs and ship it with the project (Login/Register/Profile)

Brief overview:

The core application is located directly in the main AppModule. It contains user and profile creation. Then you will find three more modules:

  • AuthModule which contains:
    • The AuthGuard used to secure GET /api/profile endpoint
    • The AuthService, JWTService and JWTAuthStrategy to process login and generate the JWT token
    • The AuthController to expose /auth endpoint to log in
  • DatabaseModule to connect to PostgreSQL. Since using an ORM was not encouraged, instead of having repositories for the different entities, I created a custom service by using pg node-postgres client for all DB queries.
  • RedisCacheModule which uses NestJS cache manager with Redis as a data store to save a cache for recently retrieved Profiles.
    • Note: I left a console log on propouse at this line to easily see if the Profile requested is comming from the Database.
    • Note: Cache time to live timer is set to 60 seconds.

Running the app:

The only pre requisite is that you need to have Docker installed in your machine. After that, you can set up the applicacion by simply running the docker containers. You can use the environment configuration file provided in this repo:

$ docker-compose --env-file service/src/utils/credentials.env up

Using the app:

  1. Create a user by doing a POST request to /api/users with the user data:
curl --location --request POST 'localhost:5000/api/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Profile Name",
    "username": "username",
    "password": "pa$$word",
    "address": "Street 1234",
    "cityId": 1
}'
  1. Before getting you profile information again, you will also need to log in by doing a POST to /auth:
curl --location --request POST 'localhost:5000/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "username",
    "password": "pa$$word"
}'
  1. All set! Now you can use the retrieved JWT token to GET you profile with /api/profile
curl --location --request GET 'http://localhost:5000/api/profile' \
--header 'Authorization: Bearer {JWT Token}'

Using the app through it's UI: new!

  1. Simply go to http://localhost:3000 and create an user.
  2. Once you have an user created, go to Login page and retrieve your profile information. Is that easy!

c001-login's People

Contributors

maurocasciati avatar

Watchers

 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.