Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
authenticate User using postgres db

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);
    }
  };

terminal
enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!