exports.signin = async (req, res) => {
const userid = req.body.userid;
const userpw = req.body.userpw;
const user = await User.findOne({ userid: userid });
if (!user) {
/* 아이디(유저)가 존재하지 않을 때 코드 구현 */
} else if (await bcrypt.compare(userpw, user.userpw)) {
/* 비밀번호가 일치할 때 코드 구현 (Login Success) */
} else {
/* 비밀번호가 일치하지 않을 때 코드 구현 */
else if(bcrypt.compare(userpw, user.userpw)) { /* ... */ }
처음엔 이렇게 작성했었는데 잘못된 비밀번호를 입력해도 자꾸 로그인 성공으로 인식해버렸다. (return값이 항상 true)
하지만 await을 붙여줘야 하는 것을 알았다!
⬇️ 참고한 사이트
https://stackoverflow.com/questions/62965515/node-bcrypt-compare-always-returns-success