title: Node js Next is not a function in passport strategy error
body: <p>Can't seem to get a login system working. I'm using a json file with the user information, and am using node.js, express and passport. Here is my code (abridged to only include the relevant information).</p>
  
  <p><strong>Index.js</strong></p>
  
  <pre><code>const express = require('express')
  const path = require('path')
  const PORT = process.env.PORT || 5000
  const myDB = require('./jDB');
  const passport = require('passport')
    , LocalStrategy = require('passport-local').Strategy;
  const app = express();
  const bodyParser = require('body-parser');
  
  app.use(express.static(path.join(__dirname, 'public')));
  app.use(bodyParser());
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  
  app.use(passport.initialize());
  app.use(passport.session());
  
  app.get('/success', (req, res) =&gt; res.send("Welcome "+req.query.username+"!!"));
  app.get('/error', (req, res) =&gt; res.send("error logging in"));
  
  passport.serializeUser(function(user, cb) {
    cb(null, user.id);
  });
  
  passport.deserializeUser(function(id, cb) {
    User.findById(id, function(err, user) {
      cb(err, user);
    });
  });
  
  passport.use(new LocalStrategy({
  
    usernameField: 'username',
    passwordfield : 'password'
  
  },
    function(username, password, done) {
    console.log('I was given ' + username + " and " + password);
    if(myDB.login(username, password)) {
        console.log('Logged in');
        return done(null, user); 
    } else {
        console.log('Failed login');
        return done(null, false);
    }
  }));
  
  
  function myAuth(req, res) {
    passport.authenticate('local', { 
      successRedirect: '/success', 
      failureRedirect: '/error', 
    })(req, res);
  
  
  }
  
  app.get('/login', (req, res) =&gt; res.render('pages/login', { root : __dirname}));
  
  app.post('/login', (req, res) =&gt; myAuth(req, res));
  
  app.listen(PORT, () =&gt; console.log(`Listening on ${ PORT }`));  
  </code></pre>
  
  <p><strong>jDB.js</strong></p>
  
  <pre><code>const login = require('./json/users.json');
  
  module.exports = {
      login : function(mUser, mPass) {
          var cryptPass = crypto.createHmac('sha256', mPass).digest('hex');
          for(var exUser in login) {
              console.log(json.stringify(login[exUser]) + " against " + mUser);
              if(login[exUser].username == mUser &amp;&amp; login[exUser].password == cryptPass) {
                  return true;
              }
          } 
          return false;
  
      }
  </code></pre>
  
  <p>And the form section of login.ejs:</p>
  
  <pre><code>&lt;form action='/login' method='post'&gt;
              &lt;div class="form-group"&gt;
                &lt;label for="username"&gt;Username&lt;/label&gt;
                &lt;input type="text" class="form-control" name="username"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                &lt;label for="pasword"&gt;Password&lt;/label&gt;
                &lt;input type="password" class="form-control" name="password"&gt;
              &lt;/div&gt;
              &lt;button type="submit" class="btn btn-primary"&gt;Login&lt;/button&gt;
            &lt;/form&gt;
  </code></pre>
  
  <p>Whenever I try and log in, with the correct username and password details, I get the following error:</p>
  
  <pre><code>TypeError: next is not a function
      at Strategy.strategy.error (/home/tommy/carrers-week/node_modules/passport/lib/middleware/authenticate.js:356:9)
      at Strategy.authenticate (/home/tommy/carrers-week/node_modules/passport-local/lib/strategy.js:93:17)
      at attempt (/home/tommy/carrers-week/node_modules/passport/lib/middleware/authenticate.js:361:16)
      at authenticate (/home/tommy/carrers-week/node_modules/passport/lib/middleware/authenticate.js:362:7)
      at myAuth (/home/tommy/carrers-week/index.js:195:5)
      at app.post (/home/tommy/carrers-week/index.js:202:34)
      at Layer.handle [as handle_request] (/home/tommy/carrers-week/node_modules/express/lib/router/layer.js:95:5)
      at next (/home/tommy/carrers-week/node_modules/express/lib/router/route.js:137:13)
      at Route.dispatch (/home/tommy/carrers-week/node_modules/express/lib/router/route.js:112:3)
      at Layer.handle [as handle_request] (/home/tommy/carrers-week/node_modules/express/lib/router/layer.js:95:5)
  </code></pre>
  
  <p>I seriously have no idea how to solve this, so thanks in advance for all your help!</p>