title: Shall I use req.user or req.session.passport
body: <p>I am using Passport for logging users in Nodejs. But when I tried to access the user by req.user, I get: Promise { pending } <br>
  However, I can get the users id with req.session.passport.user.id - Is it fine to do it that way?</p>
  
  <p>This is the promise, how can I improve it?</p>
  
  <pre><code>const getUserBy = async (what, type) =&gt; {
  
      const poolConnection =  mysql.createPool({
          host : 'localhost',
          user : 'root',
          password: 'password',
          port: 3306,
          database: 'mydb'
      });
  
  
      //FIND THE USER AND RETURN IT
      return new Promise(function (resolve, reject){
  
          poolConnection.getConnection((err, con) =&gt; {
  
              if(err) resolve(false)
  
              con.query("SELECT * FROM thetable WHERE " + type + " = ? LIMIT 1", [what], (err, row) =&gt; {
  
                  if(err) resolve(false)
  
                  //If there were no rows found
                  if(row.length != 1) resolve(null)
  
                  //Resolve the user found
                  resolve(row[0])
  
              })
  
          })
  
      })
  
  }
  
  
  
  /* INITIALIZE PASSPORT TO RETURN */
  const initialize = (passport) =&gt; {
  
      const authenticateUser = async (email, password, done) =&gt; {
  
          const user = await getUserBy(email, "EMAIL")
  
          if(user == false) return done(null, false, {message: "Unable to find this user"});
  
          if(user == null) return done(null, false, {message: "This account and password don't match"});
  
          //Check if the password match the database
          const foundPass = await bcrypt.compare(password, user.password);
  
          if(!foundPass) return done(null, false, { message: "This account and password don't match" })
  
          return done(null, user)
  
      }
  
      passport.use(new LocalStratergy({ usernameField: 'email' }, authenticateUser));
  
      passport.serializeUser((user, done) =&gt; done(null, user.id))
  
      passport.deserializeUser((id, done) =&gt; done(null, getUserBy(id, "ID")))
  
  }
  
  </code></pre>
  
  <p>I am not very sure if I should get the user using a promise, but it was the only way I made it work.</p>