0

I try to build a project with nodejs, express and mongo db. In the project a user doesn't have to register or sign up but for logging in he must enter into a form the username and password created and already inserted in mongodb by the database administrator. The administrator gives the username and the password to a user for logging in and seeing the other page. How to verify if the username and password typed in the form match to those find in the database? Help me please l'm a beginner, For authentication I'm using passport, passport-local, passport-local-mongoose

Mata28
  • 11
  • 3
  • This looks like it could help you out. https://stackoverflow.com/questions/19024878/simple-login-page-in-nodejs-using-express-and-passport-with-mongodb?rq=1 – Tim Wüstenhagen Feb 27 '21 at 13:07
  • Have you written any code or you are just looking for options on how to progess? – Apoorva Chikara Feb 27 '21 at 15:12
  • Apoorva Chikara, I tried some codes but it didn't work, I looked for some tutorials but the matter is that in almost all the tutorials they talk about the registration but in my case the user has not to register but for logging in he must use the username and the password that the enterprise for example will give him. – Mata28 Feb 28 '21 at 08:23

1 Answers1

0

You can check if this information is registered in the database or not

router.post("/login", (req, res) => {
  const user = User.findOne({username: req.body.username});
  if (user) {
    res.status(400).json({
    message: "this user is already registered",
    data: {}
    });
  };
  res.status(200).json({
    message: "login successful",
    data: user
  })
});
General Grievance
  • 4,555
  • 31
  • 31
  • 45