// 데이터베이스 안에는 회원가입 시 비밀번호가 같아도 해쉬는 랜덤이다
const hash_password = await bcrypt.hash(password, 10);
// req.bdoy.password를 해쉬시켜준다
const check = await bcrypt.compare(password, hash_password);
console.log(check);
// 불리언반환
await Signs.create({
email,
password: hash_password,
// 값을 넣어준다.
nickname,
});
res.status(201).send("회원가입 완료");
const { password, email } = req.body;
const user = await Signs.findOne({
where: { email: email },
}); //같은 이메일을 찾아주고
const isPasswordValid = await bcrypt.compare(password, user.password);
// req.body.password와 user.password를 비교해준다. 불리언반환
if (!isPasswordValid) { // 틀리다면 에러
return res.status(400).send("비밀번호를 잘못 입력하셨습니다.");
}
if (user.length === 0) { // 같은 이메일 회원이 없다면
return res.status(400).send("회원이 아닙니다.");
}
// isPasswordValid 로그인 실행
res.status(201).send("로그인 완료");
} catch (error) {
console.log(error);
}