강의

멘토링

커뮤니티

Inflearn Community Q&A

hister5597's profile image
hister5597

asked

[Renewed] Node.js Textbook - From Basics to Project Practice

Using a passport

promise에서 궁금합니다.

Written on

·

159

0

router.post('/join', async (req, res, next) => {
  const { email, nick, password } = req.body;
  try {
    const exUser = await User.findOne({ where: { email } });
    if (exUser) {
      return res.redirect('/join?error=exist');
    }
    const hash = await bcrypt.hash(password, 12);
    await User.create({
      email,
      nick,
      password: hash,
    });
    return res.redirect('/');
  } catch (error) {
    console.error(error);
    return next(error);
  }
});

여기서 User.create 앞에 await을 붙일 필요가 있을까여?

없어도 될거같아서 문의드립니다.

 

Sequelizenodejsmysqlmongodb

Answer 1

0

zerocho님의 프로필 이미지
zerocho
Instructor

붙이는 게 좋습니다. 그래야 에러가 발생했을 때 응답을 보내지 않아서 에러라는 상황을 알 수 있습니다.

hi-ster님의 프로필 이미지
hi-ster
Questioner

그냥

User.create({
      email,
      nick,
      password: hash,
  });

로만 했을때는 .then 이나 .catch가 없으니 try에 안걸리나요??

 

 

zerocho님의 프로필 이미지
zerocho
Instructor

네 안 걸리고 unhandledpromise 에러가 뜰겁니다.

hister5597's profile image
hister5597

asked

Ask a question