title: Can't get flash message to render when using connect-flash for Node/Express app
body: <p>I'm trying to render flash messages via connect-flash when users successfully login to my app.</p>
  
  <p>I can console log out the flash messages, but they don't seem to be getting rendered client side.</p>
  
  <p>However, I know for a fact that there's nothing wrong in the client side because when I replace <code>req.flash[0]</code> in my route with a simple string like <code>'You have successfully login!'</code> then the message <strong>does</strong> appear.</p>
  
  <p><strong>Passport config:</strong></p>
  
  <pre><code>// Local login Strategy
  passport.use('local-login', new LocalStrategy(
    {
      usernameField: 'email',
      passwordField: 'password',
      passReqToCallback: true
    },
    (req, email, password, done) =&gt; {
      User.findOne({ 'local.email': email })
        .then(user =&gt; {
          if (!user) return done(null, false);
  
          user.validPassword(password, (err, res) =&gt; {
            if (err) return done(err);
            if (!res) return done(null, false);
            done(null, user, req.flash('success', 'Login Successful!'));
          });
        })
        .catch(err =&gt; done(err));
    }
  ));
  </code></pre>
  
  <p><strong>Route:</strong></p>
  
  <pre><code>app.post(
      '/api/login',
      passport.authenticate('local-login'),
      (req, res) =&gt; {
        console.log(req.flash('success'));
        const user = {
          user: req.user,
          msg: req.flash('success')[0]       // Works when I replace with 'You have successfully logged in'
        };
        res.send(user);
      }
    );
  </code></pre>
  
  <p><strong>Server:</strong></p>
  
  <pre><code>const express = require('express');
  const bodyParser = require('body-parser');
  const mongoose = require('mongoose');
  const passport = require('passport');
  const flash = require('connect-flash');
  const cookieParser = require('cookie-parser');
  const cookieSession = require('cookie-session');
  const keys = require('./config/keys');
  require('./models/User');
  require('./services/passport');
  
  mongoose.connect(keys.mongoURI);
  
  const app = express();
  
  app.use(bodyParser.json());
  app.use(cookieParser());
  app.use(flash());
  
  
  app.use(
    cookieSession({
      maxAge: 30 * 24 * 60 * 60 * 1000,
      keys: [keys.cookieKey]
    })
  );
  
  app.use(passport.initialize());
  app.use(passport.session());
  
  require('./routes/authRoutes')(app);
  
  app.get('/', (req, res) =&gt; {
    res.json({ message: 'hello' });
  });
  
  if (process.env.NODE_ENV === 'production') {
    app.use(express.static('client/build'));
  
    const path = require('path');
    app.get('/', (req, res) =&gt; {
      res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
    });
  }
  
  const PORT = process.env.PORT || 5000;
  app.listen(PORT, () =&gt; console.log('Working'));
  </code></pre>