꾸준히 재밌게
article thumbnail
728x90
728x90

 

 

에러 메세지

JWT Guard설정 후 테스트를 위해 서버를 실행했을 때 발생

 

 

 

원인

그대로 번역하면 메타타입은 생성자가 아니라는 것 같음.

metatype is not a constructor에러는 커스텀 가드를 사용할 때 발생할 수 있는 일반적 오류중 하나이며

@UseGuards() 데코레이터에 가드 클래스를 전달할 때 메타타입 정보가 올바르게 전달되지 않을 때 발생한다고 한다.

즉, 인스턴스를 전달하는 것이 아니라 생성자 함수를 전달해야한다.

//before
@UseGuards(AuthGuard)

//after
@UseGuards(AuthGuard())

문제가 된 부분을 수정해주었음.

 

 

새로운 에러

In order to use "defaultStrategy", please, ensure to import PassportModule in each place where AuthGuard() is being used, Otherwise, passport won't work correctly.

 

defaultStrategy를 사용하려면 AuthGuard가 사용되는 곳에 PassportModule을 import해주어야 한다고 한다.

 

나의 경우 AuthModule에서 사용중이니 임포트 해주었다.

@Module({
    providers: [AuthService],
    controllers: [AuthController],
    exports: [AuthService],
    imports: [
      UserModule,
      //추가한 부분
      PassportModule.register({ defaultStrategy: 'jwt' }),
            
      JwtModule.registerAsync({
      (...생략...)
    ],
  })
  export class AuthModule {}

 

 

 

 

참조

https://stackoverflow.com/questions/67066064/error-metatype-is-not-a-constructor-when-using-instance-of-own-https-server-cla

 

Error: metatype is not a constructor when using instance of own HTTPS Server class

Good evening, I am playing around with nest and want to achieve an own HTTPS-Server that can be instantiated everywhere in other projects. Right at the beginning I get the following error-message:

stackoverflow.com

https://velog.io/@wanzekim/ERROR-ExceptionHandler-metatype-is-not-a-constructor

 

[Nest.js] ERROR [ExceptionHandler] metatype is not a constructor

@UseGuards(AuthGuard()) 로 발생한 이슈

velog.io

 

728x90
300x250
profile

꾸준히 재밌게

@mag1c

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!