Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda