title: How to get http request.body or request in passport LocalStrategy callback
body: <p>Just want to get http request or request.body inside the callback of LocalStrategy as you can see in the attached files we code like this
  new LocalStrategy({
              usernameField: 'email',
              passwordField: 'pwd'
            },(username: any, password: any, done: any) => {
  We are able to get username &amp; password, but I want to get entire req.body</p>
  
  <ol>
  <li>I want to get some additional information which is passed in login request and want to store this additional information as part of a session created.</li>
  <li>I tried to solve this using req.logIn() method of passport inside callback of passport.authenticate('local', callback).</li>
  <li>It worked but the problem here is the passport.serialize method is called twice hence it creates two sessions. I want to avoid double session creation.</li>
  <li>Hence the solution I thought is to get additional information LocalStrategy method.</li>
  </ol>
  
  <p>Code</p>
  
  <pre><code>import UserDetailsRepo from '../../repo/UserDetailsRepo'
  import UserDetails from '../../model/UserDetails'
  import * as passport from 'passport'
  import { Strategy as LocalStrategy } from 'passport-local'
  // import JwtConfiguration from './express-jwt-config'
  import * as HttpStatus from 'http-status-codes'
  
  class PassportAuth {
      public passport: any;
      constructor() {
          this.passport = passport.use(new LocalStrategy({
              usernameField: 'email',
              passwordField: 'pwd'
            },(username: any, password: any, done: any) =&gt; {
              UserDetailsRepo.fetch(username)
                  .then(function (userDetails: UserDetails) {
                      if (!userDetails) {
                          return done(null, false, { errorCode: HttpStatus.UNAUTHORIZED, message: 'Incorrect username.' });
                      }
                      if (!userDetails.validatePassword(password)) {
                          return done(null, false, { errorCode: HttpStatus.UNAUTHORIZED, message: 'Incorrect password.' });
                      }
                      return done(null,  userDetails);
                  })
                  .catch((err: any) =&gt; {
                      return done(err);
                  })
          }))
          // passport.use(JwtConfiguration.getStrategy())
          passport.serializeUser(function (user, done) {
              if(!user) {
                  done({ errorCode: HttpStatus.UNPROCESSABLE_ENTITY,message:'ser' },user)
              } else {
                  done(null, user);
              }
          });
  
          passport.deserializeUser(function (user, done) {
              console.log("Deseriaize User");
              console.log(user);
              done(null, user);
          });
      }
  }
  export default new PassportAuth().passport;
  
  
  router.post('/login', passport.authenticate('local'), (req: Request, res: Response, next: NextFunction) =&gt; {
              passport.authenticate('local', (err: any, user: UserDetails, info: any) =&gt; {
                  if (user) {
                      let loginUser = user.checkAttributes(req.body.role, req.body.department);
                      // if (loginUser) {
                          req.logIn(loginUser, function (err) {
                              if (err) {
                                  next(err)
                              }
                              next()
                          });
                      // } else {
                      //  next({ errorCode: HttpStatus.UNPROCESSABLE_ENTITY })
                      // }
                  } else {
                      next(info)
                  }
              })(req, res, next)
          }, (req: Request, res: Response) =&gt; {
              res.send(req.body)
              res.end()
          });
  </code></pre>