/images/profile.png

Hi i'am shy.

Nestjs: Gaurd를 이용해 Authentication/ Authorization 구현

big picture passport와 bcrypt를 이용하여 Authentication passport와 jwt를 이용하여 Authorization 1. passport와 bcrypt를 이용하여 사용자 인증 User module에 User Entity를 생성하고, User service에서 User database에 create / fetch 하는 메서드를 간단히 만들어 줍니다. UserService를 Authentication module에서 사용하길 원하기 때문에, UserService를 @Injectable() 데코레이터로 감싸주고, UserModule에서 UserService를 export해줍니다. password는 가장 안전해야 하는 데이터입니다. 그래서 password는 hash 해야 합니다. hash를 하는 과정에서 필요한 값은 random string 인 salt 값이 필요합니다. bcrypt 이 모든 과정을 bcrypt 라이브러리를 사용하면 쉽게 할 수 있습니다.