ruslanguns / nestjs-myblog

😍 NestJS + TypeORM + MySQL + Bonus: Swagger
140 stars 52 forks source link

Temario Dominicode LiveCoding 30-08-2020 #4

Closed ruslanguns closed 4 years ago

ruslanguns commented 4 years ago
  • Clonar repositorio git clone -b livecoding/2 https://github.com/ruslanguns/nestjs-myblog.git myblog

JWT STRATEGY

  • Estructura de carpetas que usaremos.
  • Configuración básica siguiendo la Documentacion oficial
  • Inyectar PassportModule
  • Crear el provider localStrategy e implementarlo conjunto al servicio
  • Mi primer Custom Decorator para obtener el usuario
  • Inyectar JwtModule
  • Implementar el provider jwtStrategy e implementarlo
  • Método de Login JWT y endpoint profile
  • Error handling con JWT en el Guard
  • Configuración para el Swagger addBearerAuth()

Requisitos:

Paquetes:

- nest-access-control
  • Modificación de UserModel para almacenar los roles
  • Creación del archivo app.roles.ts y utilizar builder
  • Inyectar el AccessControlModule en el AppModule
  • Creación del decorador wrapper
  • Implementar lógica de negocio para rutas OWN && ANY
  • Creación de una función para generar un usuario único

ROADMAP

                     
  Controller Método Ruta Info PUBLIC AUTHOR ADMIN AUTHOR POSSESION ADMIN POSSESION  
  USER GET /user Get Many YES YES YES ANY ANY  
  USER GET /user/1 Get One By ID YES YES YES ANY ANY  
  USER POST /user Create One NO YES YES OWN OWN  
  USER PUT /user/1 Edit One NO YES YES OWN ANY  
  USER DELETE /user/1 Delete One NO YES YES OWN ANY  
  USER POST /post Registration YES YES YES - -  
  POST GET /post Get Many YES YES YES ANY ANY  
  POST GET /post/1 Get One By ID YES YES YES ANY ANY  
  POST POST /post Create One NO YES YES OWN OWN  
  POST PUT /post/1 Edit One NO YES YES OWN ANY  
  POST DELETE /post/1 Delete One NO YES YES OWN ANY  
  AUTH POST /auth/login Login YES YES YES - -  
  AUTH GET /auth/profile Get me NO YES YES - -  
                     

Articles to read