Skip to content

Tobils/nestjs-jwt-auth

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

NPM Version Package License NPM Downloads Travis Linux Coverage Gitter Backers on Open Collective Sponsors on Open Collective

Deskripsi

membuat authentication dengan jwt terdiri dari module

  1. auth
  2. users

kedua modul tersebut akan dipanggil dan digunakan oleh app.controller dan app.service

  • access protected routes
  • access public routes

setalah berhasil, dilanjutkan dengan akses dan validasi data user ke database dengan route :

  • register
  • login
  • akses protected route

config & dependency

# create prject
nest new jwt_auth

# create user module
nest g module users

# create controller
nest g controller users --no-spec

# create users service
nest g service users --no-spec

npm install dotenv @nestjs/passport passport passport-local
npm install --save-dev @types/passport-local

npm install @nestjs/jwt passport-jwt
npm install @types/passport-jwt --save-dev

# create auth module
nest g module auth
nest g service auth

Testing

  • url : 127.0.0.1:3000/auth/login

  • method: POST

  • body

    {
      "username": "john",
      "password": "changeme"
    }
  • response

    {
      "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImpvaG4iLCJzdWIiOjEsImlhdCI6MTYwODY4NjE3OSwiZXhwIjoxNjA4Njg2MjM5fQ.yAb9YRwU7nCGrbxSmnqQbsQ2NqRxgaPJN6O7dwIbQXE"
    }

About

implementasi jwt auth menggunakan framework nestjs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published