Giter Club home page Giter Club logo

nestjs-auth0's Introduction

auth0 nestjs

Nestjs ๐Ÿค Auth0

Template repo for building a NestJS client of a Auth0 tenant.

Features

  • Fully functional auth module, includes 3 core routes:
  • Auth session refresh on each request.
  • Auth session validation guard and decorator (for protected endpoints)
  • Integration with auth0 for password grant and refresh token grant flows.
  • Cache support for serverless auth sessions.
  • TypeORM configuration for DB interactions.
  • Organized test files structures with centralized mocks.
  • Dockerization of all dependencies.

Base API Reference

Below you can find a simple reference to the base endpoints of the repo.

POST auth/login
  • Request URL: https://api_url/auth/login
  • HTTP Method: POST
  • Request body:
{
  // application/json
  "username": "email@domain", // email or username
  "password": "secret-pass-123"
}
  • Returns: a. Body with following structure
{
  "user": {
    "createdAt": "2024-05-01T00:00:00Z",
    "updatedAt": "2024-05-01T00:00:00Z",
    "userId": "auth0UserId",
    "username": "a unique username",
    "email": "[email protected]",
    "avatar": "auth0 managed avatar",
    "firstName": "John",
    "lastName": "Doe"
  },
  "sessionId": "uuid-string-randomly-generated" // Raw session id
}

b. Signed cookie session_id

GET auth/logout

Deletes session cookie and session. The user must re-login after calling this endpoint

  • Request URL: https://api_url/auth/logout
  • HTTP Method: GET
  • Returns:
{
  "message": "User logged out."
}
GET auth/me

Returns the currently logged user.

  • Request URL: https://api_url/auth/me
  • HTTP Method: GET
  • Returns:
{
  "createdAt": "2024-05-01T00:00:00Z",
  "updatedAt": "2024-05-01T00:00:00Z",
  "userId": "auth0UserId",
  "username": "a unique username",
  "email": "[email protected]",
  "avatar": "auth0 managed avatar",
  "firstName": "John",
  "lastName": "Doe"
}

Environment nice to have

Node 20.12.2

This project was developed with Node iron (20.12.2) and it is highly recommended to use the same version to run the project.

Docker

While not completely required. It is recommended to have a stable version of docker installed for easier setup. It is required to provision a DB server and a redis store instance. For details on the dockerization check the docker-compose.yml file.

Installation

Setup of the project includes the main NestJS app depedencies as well as dependant microservices.

$ docker compose up -d # Setups microservices
$ npm install

Environment vars provisioning

An example.env file is attached to the root of the project. You should rename it / copy to .env to store the required env vars.

$ cp example.env .env

Running the app

The server will listen on the .env specified port (default 3000) after running the following command.

# watch mode
$ npm run start:dev

Testing

# unit tests
$ npm run test

# test coverage
$ npm run test:cov

nestjs-auth0's People

Contributors

m-ivan avatar

Stargazers

Lucio Caridi 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.