nestjs2 [User] Authentication #3 JWT Middleware 사용자에게 전달된 token의 정보를 어떻게 받을 수 있을까? JWT middleware 작성 / 적용 // jwt.middleware.ts @Injectable() export class JwtMiddleware implements NestMiddleware {} // 미들웨어에 추가 // #1 app.module.ts export class AppModule implements NestModule { configure(consumer: MiddlewareConsumer) { consumer .apply(JwtMiddleware) .forRoutes({ path: '/graphql', method: RequestMethod.ALL }); } } path: '*' 전체 route에 적용할 수도 있고, m.. 2023. 4. 8. [User] Authentication #2 JWT Module 이 방법은 굳이 필요 없고 더 간단한 방법도 있으나 Nestjs의 Module 구조의 이해를 위해 작업해 봄. nest g mo jwt / nest g s jwt 를 통해 module / service 생성 JwtModule이 option을 갖고 활용할 수 있도록 Dynamic Module을 Return 하도록 Module 수정 module에서 service로 어떻게 injection 하는지는 아래와 같다. // jwt.module.ts @Module({}) @Global() // grobal 설정하면 해당 module에서 import 안해도 사용 가능. export class JwtModule { static forRoot(options: JwtModuleOptions): DynamicModule { .. 2023. 4. 7. 이전 1 다음 728x90