A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.
membuat authentication dengan jwt terdiri dari module
- auth
- 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
# 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-
url :
127.0.0.1:3000/auth/login -
method: POST
-
body
{ "username": "john", "password": "changeme" } -
response
{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImpvaG4iLCJzdWIiOjEsImlhdCI6MTYwODY4NjE3OSwiZXhwIjoxNjA4Njg2MjM5fQ.yAb9YRwU7nCGrbxSmnqQbsQ2NqRxgaPJN6O7dwIbQXE" }