title: Cannot read property 'body' of undefined in nodejs
body: <p>i have a register form in nodejs . </p>
  
  <p>in this form i must check the phoneNumber is Exsist in database or not . </p>
  
  <p>i use the <code>passportJs</code> for doing this .</p>
  
  <p>but when i send the request it show me this error : </p>
  
  <blockquote>
    <p>Cannot read property 'body' of undefined</p>
  </blockquote>
  
  <p>now i write here my code :</p>
  
  <p>this is the passport for set in middlware :</p>
  
  <pre><code>     require('./passport/passport-local');
       app.use(passport.initialize());
       app.use(passport.session())
  </code></pre>
  
  <p>this is the <code>passport-local</code> file in my project :</p>
  
  <pre><code>    const passport = require('passport');
  const localStrategy = require('passport-local').Strategy;
  const UserModel = require('../models/users')
  
  passport.serializeUser(function(user, done) {
      done(null, user.id);
    });
  
    passport.deserializeUser(function(id, done) {
      User.findById(id, function(err, user) {
        done(err, user);
      });
    });
  
  passport.use('local.register', new localStrategy({
      phoneNumberField: 'phoneNumber',
      passReqToCallback: true,
  }, (req, phoneNumber, done) =&gt; {
      UserModel.findOne({ phoneNumber: phoneNumber }, (error, user) =&gt; {
          if (error) return done(error);
          if (!user) return done(error, false, req.flash('errors', 'This Phone Number exist . Please Choose the Other Phone Number'))
  
          const addUSer = new UserModel({
              name: req.body.name,
              family: req.body.family,
              phoneNumber: req.body.phoneNumber,
              password: req.body.password
          })
  
          addUSer.save((err) =&gt; {
              if (err) return done(err, false, req.flash('errors', 'امکان ثبت کاربر با این مشخصات وجود ندارد'));
              done(null, addUSer);
          });
      })
  }))
  </code></pre>
  
  <p>and this is my controller :</p>
  
  <pre><code>   RegisterProcess(req, res) {
  
      var validateResult = validationResult(req);
  
      if (!validateResult.isEmpty()) {
          const errors = validateResult.array();
          let messages = [];
          errors.forEach(error =&gt; {
              messages.push(error.msg);
          });
          req.flash('errors', messages)
          res.redirect('/auth/register');
      }else{
          this.register();
      }
  }
  
  register(req, res, next) {
      passport.authenticate('local.register', {
          successRedirect: '/admin',
          failureRedirect: '/auth/register',
          failureMessage: true
      })(req, res, next)
  }
  </code></pre>
  
  <p>now whats the problem ? how can i solve this problem ???</p>
  
  <p>**Edit : **</p>
  
  <p>Full Stack Trace :</p>
  
  <pre><code>TypeError: Cannot read property 'body' of undefined
  at Strategy.authenticate (/home/mrcoder/Projects/Nodejs/OnlineStore/node_modules/passport-local/lib/strategy.js:71:29)
  at attempt (/home/mrcoder/Projects/Nodejs/OnlineStore/node_modules/passport/lib/middleware/authenticate.js:366:16)
  at authenticate (/home/mrcoder/Projects/Nodejs/OnlineStore/node_modules/passport/lib/middleware/authenticate.js:367:7)
  at RegisterController.register (/home/mrcoder/Projects/Nodejs/OnlineStore/app/http/controller/auth/RegisterController.js:36:11)
  at RegisterController.RegisterProcess (/home/mrcoder/Projects/Nodejs/OnlineStore/app/http/controller/auth/RegisterController.js:27:18)
  at Layer.handle [as handle_request] (/home/mrcoder/Projects/Nodejs/OnlineStore/node_modules/express/lib/router/layer.js:95:5)
  at next (/home/mrcoder/Projects/Nodejs/OnlineStore/node_modules/express/lib/router/route.js:137:13)
  at middleware (/home/mrcoder/Projects/Nodejs/OnlineStore/node_modules/express-validator/src/middlewares/check.js:15:13)
  at processTicksAndRejections (internal/process/task_queues.js:97:5)
  </code></pre>