title: how to retrieve user data after implementing passport js
body: <p>I am just learning passport js with express and I did this</p>
  <pre><code>module.exports = function(passport){
      passport.use(new LocalStrategy({usernameField:'email'},(email,password,done)=&gt;{
          //match user
          UserSignup.findOne({email:email})
          .then(user=&gt;{
              if(!user){
                  return done(null,false,{message:&quot;email is not there&quot;})
              }
              bcrypt.compare(password.user.password,(err,isMatch)=&gt;{
                  if(err) throw err;
                  if(isMatch){
                      return done(null,user)
                  }
                  else{
                      return done(null,false, {message:&quot;password incorrect&quot;})
                  }
              });
          })
          .catch(err=&gt;console.log(err))
      }))
      passport.serializeUser((user,done)=&gt;{
          done(null,user.id);
      })    
      passport.deserializeUser((id,done)=&gt;{
          UserSignup.findById(id,function(err,user){
              done(err,user);
          })
      })
  }
  </code></pre>
  <p>this is passportConfig in this if everything goes well it will return user
  then how can I get this user so that i can do some operation on this like after user loged in i have to generate token and pass it to headers</p>
  <pre><code>router.post('/login',loginwithpassport);
  </code></pre>
  <p>this is my router</p>
  <pre><code>const loginwithpassport = (req,res)=&gt;{
      try {
           passport.authenticate('local')
          res.status(200).json(&quot;User loged in from controller&quot;)
          
      } catch (error) {
          console.log(error);
          res.status(403).json({
              message:error.message
          })
      }
  }
  </code></pre>
  <p>and this is my controller of login
  in controller of login how can i get user from passportConfig
  plese help</p>