Within my rendered Nunjucks template, I have set it up to accept a username and password input from the user. Upon clicking the submit button, the goal is for the system to search through a database in my JavaScript Express file to verify if the entered credentials match any records.
However, I am encountering an error message that has been puzzling me.
I have carefully checked for spelling errors or other issues, but I am unsure of how to resolve this particular error. The specific error message reads:
Error: Illegal arguments: undefined, undefined at Object.bcrypt.compareSync
The code snippet in my Express file responsible for handling the submission process is as follows:
let usersdb = new DataStore({filename: __dirname + '/usersDB', autoload: true});
app.post('/user', express.urlencoded({extended:true}), function (req, res) {
console.log(req.body);
let username = req.body.username;
let password = req.body.password;
// Find user
let auser = usersdb.find(function (user) {
return user.username === username
});
if (!auser) {// Not found
res.render("loginError.njk");
return;
}
//**** It seems like the error occurs on the following line *****
let verified = bcrypt.compareSync(password, auser.passHash);
if (verified) {
let oldInfo = req.session.user;
req.session.regenerate(function (err) {
if (err) {
console.log(err);
}
req.session.user = Object.assign(oldInfo, auser, {
loggedin: true
});
res.render("welcome.njk", {user: auser});
});
} else {
res.render("loginError.njk");
}
});
My expectation is that when a user enters their username and password on the Nunjucks page, and if these match valid entries in the usersdb, the system should render the welcome page. Otherwise, it should display the login error page.
Your assistance with this matter would be greatly appreciated!