title: nodejs-passport : done is not a function
body: <p>I am having the "done is not a function" error. I tried to remove the passReqToCallback parameter but it still doesn't work. I am not sure why please help.</p>
  
  <p>It's on the line: return done(null, false, req.flash('signupMessage', 'That username is already taken.')); </p>
  
  <pre><code>// =========================================================================
  // LOCAL SIGNUP ============================================================
  // =========================================================================
  // we are using named strategies since we have one for login and one for signup
  // by default, if there was no name, it would just be called 'local'
  
  passport.use('local-signup', new LocalStrategy({
      // by default, local strategy uses username and password, we will override with email
      emailField : 'email',
      usernameField : 'username',
      passwordField : 'password',
      passReqToCallback : true // allows us to pass back the entire request to the callback
  },
  function(req, email, username, password, done) {
  
      // asynchronous
      // User.findOne wont fire unless data is sent back
      process.nextTick(function() {
  
      // find a user whose email is the same as the forms email
      // we are checking to see if the user trying to login already exists
      User.find({ 'local.email' :  email, 'local.username' : username }, function(err, user) {
          // if there are any errors, return the error
          if (err)
              return done(err);
  
          // check to see if theres already a user with that email
          //if user found.
          if (user.length!=0) {
              if(user[0].username){
                  return done(null, false, req.flash('signupMessage', 'That username is already taken.'));                         
              }else{
                  return done(null, false, req.flash('signupMessage', 'That email is already taken.'));     
              }                                    
              return done(err);
          }
          else {
  
              // if there is no user with that email
              // create the user
              var newUser            = new User();
  
              // set the user's local credentials
              newUser.local.email    = email;
              newUser.local.username = username;
              newUser.local.password = newUser.generateHash(password);
  
              // save the user
              newUser.save(function(err) {
                  if (err)
                      throw err;
                  return done(null, true);
              });
          }
  
      });    
  
      });
  
  }));
  
      // =========================================================================
  // LOCAL LOGIN =============================================================
  // =========================================================================
  // we are using named strategies since we have one for login and one for signup
  // by default, if there was no name, it would just be called 'local'
  
  passport.use('local-login', new LocalStrategy({
      // by default, local strategy uses username and password, we will override with email
      usernameField : 'userIdentityField',
      passwordField : 'password',
      passReqToCallback : true // allows us to pass back the entire request to the callback
  },
  function(req, email, password, done) { // callback with email and password from our form
  
      // find a user whose email is the same as the forms email
      // we are checking to see if the user trying to login already exists
      User.isValidUserPassword(email, password, done);
  
  }));
  </code></pre>
  
  <p>};</p>