Taken from the passport.js docs; for example sake, change the usernameField to username, passwordField to password. You could probaly switch the User object with the variable assignments for login results with database results if you so desire.
var username = ibm d2 query results for username;
var password = ibm d2 query results for password;
var User = {//login form username/password
username: '', //whatever they entered will go here,
password: ''
};
....
// the above is passed as arguments to the
function(username, password, done) {
User is the object returned from your login form. findOne is a
passportJs function that compare the value of your username property
to the database query results you assigned to variable username. If match
is success and not err, the results are passed as the user object to the
next function.
function(username, password, done) {
User.findOne({ username: username }, function(err, user) {
if (err) { return done(err); }
if (!user) {
return done(null, false, { message: 'Incorrect username.' });
}
if (!user.validPassword(password)) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
});
}
));
function returns user object results if no errors are present and
match was found. Note, this is error first style so he returns a null
value for a successful result as opposed to just the result. null in
this case meaning no errors.