강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của lhb19951521
lhb19951521

câu hỏi đã được viết

NestJS phụ trợ vững chắc, từ cơ bản đến nâng cao

chiến lược xác thực và hộ chiếu & Trang trí tùy chỉnh

500 에러 발생

Đã giải quyết

Viết

·

332

1

안녕하세요

payload의 sub를 넘겨 레포지토리에서 함수를 실행하는 부분이 자꾸 500에러가 뜹니다.

ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'findUserByIdWithoutPwd')

TypeError: Cannot read properties of undefined (reading 'findUserByIdWithoutPwd')

로 프로퍼티 undefined 오류가 발생하는데 어디를 확인해 봐야 좋을까요? 우선 startegy 파일과 repository 파일, Payload 파일에서 관련된 코드는 아래와 같습니다.

 

async validate(payload: Payload) {
    const user = await this.userRepository.findUserByIdWithoutPwd(payload.sub);

    if (user) {
      return user; // request.user안에 user가 들어감
    } else {
      throw new UnauthorizedException('접근 오류입니다');
    }
  }
  async findUserByIdWithoutPwd(subId: string): Promise<User | null> {
    const user = await this.userModel.findById(subId).select('-password');
    return user;
  }
export type Payload = {
  id: string;
  sub: string;
};

   아 그리고 저는 email이 아닌 id로 회원가입 서비스를 만들어서 서브를 아래처럼 받았는데 그래서 오류가 난 걸까요?

 

    const payload = { id: id, sub: user._id };
    return {
      token: this.jwtService.sign(payload),
    };
expressnodejsmongodbssrNestJS

Câu trả lời 1

4

bee님의 프로필 이미지
bee
Người đặt câu hỏi

거의 두 시간을 버렸는데 auth.service에 @Injectable()을 달지 않아서 생긴 오류였습니다... 혹시 추후 저처럼 에러 발생하시는 분들은 DI 확인해 보세요 ㅎ... 

Hình ảnh hồ sơ của lhb19951521
lhb19951521

câu hỏi đã được viết

Đặt câu hỏi