npm install bcryptjs --save
* salt => 같은비밀번호를 입력해도 다른 해시값이 저장되도록
import * as bcrypt from 'bcryptjs'
@Injectable()
export class UserRepository extends Repository<User>{
...
async createUser(authCredentialsDto : AuthCredentialsDto){
const {username, password} = authCredentialsDto;
const salt = await bcrypt.genSalt();
const hashedPassword = await bcrypt.hash(password, salt);
const user = this.create({username,password : hashedPassword}); //리포지토리.create => db저장용객체로 만들어줌
try {
await this.save(user);
...
}
* 로그인도 수정
if(!await bcrypt.compare(password, findMember.password)){
console.log('비밀번호 불일치');
return "redirect:user/login_failed";
}
'JS > Nest.js' 카테고리의 다른 글
[Nest JS] JWT => accessToken 발급 (0) | 2024.08.18 |
---|---|
[Nest JS] 로그인 구현 / bcrypt.compare salt issue (0) | 2024.08.18 |
[Nest JS] id 중복검사 구현 (0) | 2024.08.18 |
[Nest JS] 유효성체크 with class-validator, 파이프 (0) | 2024.08.18 |
[Nest JS] 회원가입 구현 / TypeError: this.userRepository.createUser is not a function 해결 (0) | 2024.08.18 |