강의

멘토링

커뮤니티

Inflearn Community Q&A

gcy's profile image
gcy

asked

Node and React series that you can learn by following - Basic lecture

Node React Basics Lecture #10 Encrypting Passwords with Bcrypt

계속하여 암호화에 실패해요

Written on

·

440

1

{

    "success": false,

    "err": {}

}

포스트맨 결과입니다.

제 아래 코드에요 ㅠㅠ....


userSchema.pre("save"next => {
  var user = this;

  if (user.isModified("password")) {
    //비밀번호 암호화 시킨다
    bcrypt.genSalt(saltRounds, (errsalt=> {
      if (errreturn next(err);

      bcrypt.hash(user.passwordsalt, (errhash=> {
        if (errreturn next(err);

        user.password = hash;
        next();
      });
    });
  }
});
nodejsreact

Answer 4

0

user를 this로 정해주었는데 기본적으로 arrow function 에서는 this바인딩이 안되고 상위 scope를 this로 지정주니까 user가 다른걸로 정해져서 그런거 아닐까요..?? 일반적인 function(){}형식의 함수에서는 this바인딩이 가능하니까

0

저도 해당 내용으로 해결했는데요, 왜 차이가 생기는지 아시나요?

0

John Ahn님의 프로필 이미지
John Ahn
Instructor

아 넵 ^^ !! 수고하셨습니다 ~ ! 

0

gcy님의 프로필 이미지
gcy
Questioner

next => {} 를 function(next)로 바꾸니까 해결됐습니다!..

gcy's profile image
gcy

asked

Ask a question