Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda