Git Product home page Git Product logo

take-home-auth-nestjs's Introduction

Description

A take home project build with Nest.js:

  • Jwt auth strategy via passport-jwt
  • Session auth strategy via passport-local, express-session, and Redis to store session data
  • PostgreSQL to handle user data
  • Swagger for API documentation and testings

The project has monorepo structure. The auth-app microservice in apps directory implements the functional described above.

I'd greatly appreciate any feedback you can provide.

Installation

$ npm install

Before running the app

Before running the app, launch the docker-compose:

$ docker-compose up -d

Running the app

$ npm run start:dev auth-app

Testing the app

Once the app is up and running, open the browser at the localhost:3000/api. The Swagger interface should be loaded.

POST /login endpoint

In the auth section, access the /login endpoint by providing the user email and password in the body. The postgre db is already seeded with a few users. For example, you can use the following credentials:

{
  "email": "[email protected]",
  "password": "password-test"
}

The response should provide an access token. Copy this token and open Authorize modal (green button at the top right corner on the same page). Paste the token.

GET /users enpoint

Now, the protected routes are avaible for you to play with. For example, you can try /users endpoint to get all the users from the database.

POST /users endpoint

To register in the app, use /user enpoint and provide a body in the following format:

{
  "name": "Andrei",
  "email": "[email protected]",
  "password": "qwerty123"
}

After that you can use the /login endpoint to get the access token for the protected routes. Note that the email should be of the correct format, otherwise the login function will throw an error.

References

  1. Nest.js Official Documentation
  2. Passport.js Official Documentation
  3. An artical on prisma.io "Building a REST API with NestJS and Prisma"

take-home-auth-nestjs's People

Contributors

andreyxdd avatar

Stargazers

Mahabub 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.