Skip to content

AloisCRR/nestjs-auth0-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auth0 X NestJS

Project to test integration between Auth0 and NestJS framework, also having a frontend to test roles and permissions.

Features

  • Auth0 register and login
  • Auth0 RBAC
  • Notes C.R.U.D
  • Admin support

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

Name Description
AUTH0_DOMAIN Go to manage.auth0.com > Applications > APIs > Select your previously created API > Quick Start > Select Node.js tab. Should look something like this:
Auth0 Domain
AUTH0_AUDIENCE Go to manage.auth0.com > Applications > APIs > Select your previously created API > Settings. Should look something like this:
Auth0 Audience
REACT_APP_AUTH0_DOMAIN Same as AUTH0_DOMAIN
REACT_APP_AUTH0_AUDIENCE Same as AUTH0_AUDIENCE
REACT_APP_AUTH0_CLIENT_ID Go to manage.auth0.com > Applications > Applications > Select your previously created SPA application > Settings. Should look something like this:
Auth0 React Audience

Run Locally

  • I start from the premise that you have already created an Auth0 account, an API and also a SPA application (from Auth0 dashboard).

  • Add some roles and permissions to your Auth0 API:

Roles Permissions
Auth0 Roles Auth0 Permissions
  1. Install:

  2. Clone the project:

    git clone https://github.com/AloisCRR/nestjs-auth0-integration.git
  3. Go to the project directory:

    cd nestjs-auth0-integration
  4. Install dependencies:

    npm install
  5. Start NestJS and React dev servers by running:

    npm run api
    npm run app

API Reference

Note entity

Note creation

POST /notes
Headers Type Description
Authentication Bearer token Required. Access token given by Auth0
Body Type Description
title string Required. Note title
note string Required. Note content
Response Type Description
Note Note Created note

Get all notes

GET /notes
Headers Type Description
Authentication Bearer token Required. Access token given by Auth0
Response Type Description
Notes Note[] Private notes of some user

Note update

PUT /notes/${id}
Parameter Type Description
id string Required. Note ID
Headers Type Description
Authentication Bearer token Required. Access token given by Auth0
Response Type Description
Note Note Updated note

Get single note

GET /notes/${id}
Parameter Type Description
id string Required. Note ID
Headers Type Description
Authentication Bearer token Required. Access token given by Auth0
Response Type Description
Note Note Note of user by it's ID

Delete note

DELETE /notes/${id}
Parameter Type Description
id string Required. Note ID
Headers Type Description
Authentication Bearer token Required. Access token given by Auth0

Screenshots

Admin view

Tech Stack

Name Description
Auth0 Flexible, drop-in solution to add authentication and authorization services to your applications.
React Frontend
NestJS Progressive Node.js framework for building efficient, reliable and scalable server-side applications

Roadmap

  • App functionality
  • Add better css support (CSS-in-JS...)
  • Testing
  • Hosting, domain, etc.
  • CI/CD

Appendix

  • To add new packages run:

    npm run add -- [app|api] somepackage