Skip to content

dinno7/auth_nestjs

Repository files navigation

Nest Logo + OAuth2 Logo

Best practice Authentication & Authorization implementation


Navigation

What we have here?

  • NestJs
  • Prisma as ORM
  • Zod for input validation
  • JWT tokens(Access & Refresh tokens)
  • Redis for auto-detection refresh token system

Installation

You need to install and run postgresql as database and redis for auto detection refresh token system. if you are not installed and run them you can use docker-compose.yml file which i provide it for you:

$ docker compose up -d

You can run separatly by below command too:

$ docker compose up -d redis
$ docker compose up -d db

Run above command just if you do not have postgres & redis on your system.

$ git clone https://github.com/dinno7/auth_nestjs
$ cd auth_nestjs
$ npm install

Running the app

# development watch mode
$ npm run start:dev

# development
$ npm run start

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Features

Auth decorator:

You can use @Auth(...AuthTypes) decorator to define authentication system for special route's handler or controller, The JWT Bearer token is active for all routes by default and you can deactive it by passing AuthTypes.None to @Auth() decorator:

// Some route handler in controller
@Auth(AuthTypes.None)
routeHandler(){
  // Your codes...
}

Also you can append this @Auth decorator to hole controller:

// Some controller
@Auth(AuthTypes.None)
@Controller('dinno')
export class DinnoController {
  // ...
}

Available Auth types:

There is 3 type of Auth types:

AuthTypes.None;
AuthTypes.Bearer; // -> Appended to all routes by default
AuthTypes.ApiKey;

To-dos

  • ApiKey auth system
  • Google OAuth2
  • OTP login with email
  • Add global exception filter
  • Complete README.md
  • Remove the forgot-pass .ejs file and replace it with simple template

License

Nest is MIT licensed.

About

Best practice Authentication & Authorization project with NestJs & Prisma as a ORM

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published