title: Error Unknown authentication strategy "local"
body: <p>I am trying to use passport to authenticate my user when they login. However, it keeps on displaying the below error. Any ideas on how to fix this. I have included my mongo-connect.js file and index.js file below for reference.</p>
  <p>Thanks in advance,</p>
  <p>Error: Unknown authentication strategy &quot;local&quot;
  at attempt (C:\Users\west5\OneDrive\Education\Masters - Information Technology (Networking + Data Science)\SIT780 - Enterprise Applications Development\Practical_3\node_modules\passport\lib\middleware\authenticate.js:184:39)
  at authenticate (C:\Users\west5\OneDrive\Education\Masters - Information Technology (Networking + Data Science)\SIT780 - Enterprise Applications Development\Practical_3\node_modules\passport\lib\middleware\authenticate.js:361:7)</p>
  <hr />
  <p>mongo-connect.js</p>
  <pre><code>const mongoose = require('mongoose');
  const passportLocalMongoose = require('passport-local-mongoose');
  
  mongoose.connect('mongodb://localhost/MyDatabase',
  { userNewURLParser: true, useUnifiedTopology: true });
  
  const Schema = mongoose.Schema;
  const UserDetail = new Schema({
  username: String, 
  password: String
  });
  
  UserDetail.plugin(passportLocalMongoose);
  const UserDetails = mongoose.model('userInfor', UserDetail, 
  'userInfor');
  
  
  const passport = require('passport');
  passport.use(UserDetails.createStrategy());
  
  passport.serializeUser(UserDetails.serializeUser());
  passport.deserializeUser(UserDetails.deserializeUser());
  
  passport.use(new LocalStrategy({
  username: 'email'
   }, register));
  
  UserDetails.register({username:'Scotty', active: false}, 'helloworld');
  UserDetails.register({username:'Timmy', active: false}, 'helloworld1');
  UserDetails.register({username:'Jason', active: false}, 'helloworld2');
  </code></pre>
  <hr />
  <p>index.js</p>
  <pre><code>const express = require('express');
  const app = express();
  
  app.use(express.static(__dirname));
  
  const bodyParser = require('body-parser');
  const expressSession = require('express-session')({
  secret: 'secret',
  resave: false, 
  saveUninitialized: false
  });
  
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true}));
  app.use(expressSession);
  
  const port = process.env.PORT || 3000;
  app.listen(port, () =&gt; console.log(`App listening on port ` + port));
  
  
  const passport = require('passport');
  
  app.use(passport.initialize());
  app.use(passport.session());
  
  
  
  const connectEnsureLogin = require('connect-ensure-login');
  const { connect } = require('mongoose');
  
  app.post('/login', (req, res, next) =&gt; {
  passport.authenticate('local',
  (err, user, info) =&gt; {
      if (err) {
          return next(err);
      }
  
      if (!user) {
          return res.redirect('/login?info=' + info);
      }
  
      req.login(user, function(err) {
          if (err) {
              return next(err);
          }
  
          return res.redirect('/');
      });
  })(req, res, next);
  });
  
  
  app.get('/login',
  (req, res) =&gt; res.sendFile('html/login.html',
  { root: __dirname})
  );
  
  app.get('/',
  connectEnsureLogin.ensureLoggedIn(),
  (req, res) =&gt; res.sendFile('html/index.html', {root: _dirname})
  );
  
  app.get('/private', 
  connectEnsureLogin.ensureLoggedIn(),
  (req, res) =&gt; res.sendFile('html/privatee.html', {root: _dirname})
  );
  
  app.get('/user', 
  connectEnsureLogin.ensureLoggedIn(),
  (req, res) =&gt; res.send({user: req.user})
  );
  
  app.post('/logout', (req, res, next) =&gt; {
  passport.authenticate('local',
  (err, user, info) =&gt; {
      if (err) {
      return next(err);
      }
  
      req.logout();
      return res.redirect('/');
  
  })(req, res, next);
  });
  </code></pre>
  <p>enter code here</p>