title: Passport and connect-flash: req.flash is not a function
body: <p>I'm learning <code>flash</code> messaging in <code>passport</code> and got stuck on this error when running my script:</p>
  
  <pre><code>req.flash is not a function
  </code></pre>
  
  <p>Here is my configuration:</p>
  
  <pre><code>var flash=require("connect-flash");
  app.use(flash());
  
  passport.use(new LocalStrategy(function(req,username, password,done) {
  process.nextTick(function() {
      UserDetails.findOne({'username': username}, function(err, user) {
          if (err) {
              return done(err);
          }          
          if (!user) {
              return done(null, false,req.flash('message','Invalid username or password'));
          }
          if (user.password != password) {
              return done(null, false,req.flash('message','Invalid username or password' ));
          }
          return done(null, user);
      });
  });
  }));
  </code></pre>
  
  <p>My route:</p>
  
  <pre><code>app.get('/', function (req, res) {
  res.render('login',{ message: req.flash('message') });
  });
  </code></pre>
  
  <p>My strategy:</p>
  
  <pre><code>app.post('/login', function(req,res,next){
  passport.authenticate('local', function(err, user) {
      if (err) { return next(err); }
      if (!user) { return res.redirect('/')}
      req.logIn(user, function(err) {
          if (err) { return next(err); } 
              arenderFunction(req,res);
          });
      })
  (req, res, next);
  });
  </code></pre>
  
  <p>Any help is much appreciated!</p>