0

Nodejs、Express、MongoDB でログイン システムを構築しています。ログインボタンをクリックすると、「あなたは確認されていません」ページにリダイレクトされ続けました。何が起こっているのかを確認するためにパスワードをコンソールログに記録することにしました。ユーザーが入力したパスワードとデータベースに保存されているパスワードが何らかの理由で未定義 (console.logs の時点で未定義) になっています。どうすればこれを修正できますか?

app.post("/login", (req, res) => {
  //Get user fields
  const userEmail = req.body.loginEmail;
  const userPass = req.body.userPass;
  //Is user in database?
  User.find({ email: userEmail }, (err, user) => {
    if (!err) {
      //Compare password to database password
      bcrypt.compare(userPass, user.password, (err, result) => {
        console.log(user.pasword);
        console.log(userPass);
        //If user pass in database, check if verified & redirect to success
        if (userPass === user.password) {
          if (user.isVerified) {
            res.redirect("/success");
          } else {
            res.send(
              "You are not verified. Please check your email to access your account."
            );
          }
        } else {
          res.send("Incorrect password");
        }
      });
    } else {
      res.send(err);
    }
  });
});
4

0 に答える 0