I'm trying to authenticate User the problem is in app.js did not return the user data, when I try to console log the user in passport-config.js I got undefined, I did the same thing with MongoDB its wonkıng properly when I change it to Postgres I got this problem
app.js
initializePassport(
passport,
async (email) => {
let sql = `SELECT * FROM users WHERE email = '${email}'`;
await db.query(sql, (err, result) => {
if(err) throw err;
let userFound = result.rows[0]
console.log(userFound)
return userFound;
})
},
async (id) => {
let sql = `SELECT * FROM users WHERE userid = '${id}'`;
await db.query(sql, (err, userFound) => {
if(err) throw err;
return userFound.rows[0] ;
})
}
);
passport-config
function initialize(passport, getUserByEmail, getUserById) {
const authenticateUser = async (email, password, done) => {
const user = await getUserByEmail(email);
console.log(user)
if (user == null) {
return done(null, false, { message: "No user with that email" });
}
if (user.verified == false) {
return done(null, false, { message: "Email hasn't been verified yet" });
}
try {
if (await bcrypt.compare(password, user.password)) {
return done(null, user);
} else {
return done(null, false, { message: "Password incorrect" });
}
} catch (err) {
return done(err);
}
};