to preface this, as I’m sure this will be a walk in the park for 99% of you guys, I’m quite new to JS and want to ensure I’m using all the syntactic sugar that I can to be up-to-date when the time comes for interviews and job prep etc.
As such, I was hoping someone would kindly help me turn the below app.post request, from a Promise .then, into an async / await (try, catch) function.
As a side-note, this small block is forming a very basic user authentication to a Mongo DB. I have a block of code that’s for a new user to register, and I can write that with async / await just fine. I’m struggling with this part somehow.
app.post("/login", (req, res) => {
const username = req.body.username;
const password = req.body.password;
User.findOne({ email: username })
.then((foundUser) => {
if (foundUser.password === password) {
res.render("secrets");
}
})
.catch((err) => {
console.log(err);
});
});
I have essentially tried writing this a number of times and keep rendering the (err) instead of the page I want.