title: ERROR: req.logIn is not a function Passport Js MERN STACK
body: <p>I am trying use passport-local to authenticate user for a MERN Stack project. Currently I am unable to LOG IN or LOG OUT and I keep getting errors like this:</p>
  <p><strong>TypeError: req.logIn is not a function</strong> &amp; <strong>req.logOut is not a function</strong></p>
  <p>I am not sure why is this happening. I have been following the Passport Js documentation. What should I do to fix this?
  Thank you</p>
  <pre><code>const express = require(&quot;express&quot;);
  const app = express();
  const cors = require(&quot;cors&quot;);
  const mongoose = require(&quot;mongoose&quot;);
  const passport = require(&quot;passport&quot;);
  const passportLocal = require(&quot;passport-local&quot;).Strategy;
  const initialize = require(&quot;./passport-config&quot;);
  const session = require(&quot;express-session&quot;);
  const bcrypt = require(&quot;bcrypt&quot;);
  const User = require(&quot;./modules/User&quot;);
  const port = XXXXX;
  
  mongoose.connect(
    &quot;XXXXXXXXXX&quot;,
    { useNewUrlParser: true },
    () =&gt; console.log(&quot;Mongoose Connected&quot;),
  );
  
  app.use(express.urlencoded({ extended: true }));
  app.use(express.json());
  app.use(cors());
  app.use(
    session({
      secret: &quot;secret&quot;,
      resave: false,
      saveUninitialized: false,
    }),
  );
  
  passport.use(passport.initialize());
  passport.use(passport.session());
  initialize(passport);
  
  app.get(&quot;/users&quot;, (req, res) =&gt; {
    res.send(&quot;Hello&quot;);
  });
  
  app.post(&quot;/users/create&quot;, (req, res) =&gt; {
    User.findOne(
      { username: req.body.username },
      async (err, doc) =&gt; {
        if (err) throw err;
        if (doc) {
          res.json({
            auth: false,
            message: &quot;User Already Exist&quot;,
          });
        } else {
          const hashedPassword = await bcrypt.hash(
            req.body.password,
            10,
          );
  
          const newUser = User({
            username: req.body.username,
            password: hashedPassword,
          });
  
          await newUser.save();
  
          res.json({
            auth: true,
            message: &quot;User Created&quot;,
          });
          console.log(&quot;User Created&quot;);
        }
      },
    );
  });
  
  app.get(&quot;/users/logout&quot;, (req, res) =&gt; {
    req.logOut();
    res.send(true);
    console.log(&quot;Logged Out&quot;);
  });
  
  app.post(&quot;/users/login&quot;, (req, res, next) =&gt; {
    passport.authenticate(&quot;local&quot;, (err, user, info) =&gt; {
      if (err) {
        return next(err);
      }
  
      if (!user) {
        res.json({
          auth: true,
          message: &quot;Cannot Log In&quot;,
        });
      }
  
      req.logIn(user, (err) =&gt; {
        if (err) {
          return next(err);
        }
        res.json({
          auth: true,
          message: &quot;User Logged In&quot;,
        });
        console.log(&quot;Successfully Logged In&quot;);
      });
    })(res, req, next);
  });
  
  app.listen(port, () =&gt;
    console.log(`Server started on port: ${port}`),
  );
  </code></pre>