NestJS: Authentication With JWT and Postgres | by Kevin Vogel | Mar, 2022

Construct a NestJS app for authentication with Postgres, JWT, and surroundings variables

NestJS Authenfication API
$ psql postgres
$ CREATE DATABASE nest_auth_api;
$ l
$ q

Command Rationalization:

$ npm i -g @nestjs/cli
$ nest new nest-auth-api -p npm
$ cd nest-auth-api
$ code .
$ git add .
$ git commit -m "chore(): init nest.js"

Putting in Dependencies

$ npm i @nestjs/config @nestjs/typeorm @nestjs/jwt @nestjs/passport passport-jwt typeorm pg passport class-transformer class-validator class-sanitizer bcryptjs
$ npm i -D @sorts/passport-jwt @sorts/node

Create Undertaking Construction

$ mkdir src/shared && mkdir src/shared/typeorm
$ mkdir src/widespread && mkdir src/widespread/envs && mkdir src/widespread/helper
$ contact src/shared/typeorm/typeorm.service.ts
$ contact src/widespread/envs/growth.env
$ contact src/widespread/helper/env.helper.ts
$ nest g mo api
$ nest g mo api/person && nest g co api/person
--no-spec && nest g s api/person --no-spec
$ nest g mo api/person/auth && nest g co api/person/auth
--no-spec && nest g s api/person/auth --no-spec
$ contact src/api/person/person.dto.ts
$ contact src/api/person/person.entity.ts
$ contact src/api/person/auth/auth.dto.ts
$ contact src/api/person/auth/auth.guard.ts
$ contact src/api/person/auth/auth.helper.ts
$ contact src/api/person/auth/auth.technique.ts

Atmosphere Variables

nest-cli.json
nest-cli.json
src/widespread/helper/env.helper.ts
src/widespread/envs/growth.env

Alias Paths

tsconfig.json
tsconfig.json

Configuration and Connect with Database (Postgres)

src/shared/typeorm/typeorm.service.ts
src/app.module.ts
src/app.module.ts
$ npm run begin:dev

Person Entity

src/api/person/person.entity.ts

AuthHelper Class

src/api/person/auth/auth.helper.ts

Guard

src/api/person/auth/auth.guard.ts

JWT Technique

src/api/person/auth/auth.technique.ts

Auth Service

src/api/person/auth/auth.service.ts
src/api/person/auth/auth.service.ts

Validation

src/api/person/auth/auth.dto.ts

Auth Controller

src/api/person/auth/auth.controller.ts
src/api/person/auth/auth.controller.ts

Auth Module

src/api/person/auth/auth.module.ts
src/api/person/auth/auth.module.ts

Validation

src/api/person/person.dto.ts

Service

src/api/person/person.service.ts
src/api/person/person.service.ts

Controller

src/api/person/person.controller.ts
src/api/person/person.controller.ts

Module

src/api/person/person.module.ts
src/api/person/person.module.ts

More Posts