title: Displaying login error messages from passport.js on ejs
body: <p>my ignorance is not letting me display login error messages on passport.js . I'd like to pass to my ejs login page the <code>message</code>  defined on <code>passport.use</code> , but I get lost in the flow, for I'm not sure who is handling the done function, but I understand that somehow it is connected to the <code>passport.authenticate</code>.</p>
  <p>It seems that <code>failureRedirect</code> is calling res.render under the hood, and it would be nice to be able to pass to it the message from the passport.use</p>
  <p>I tried unsuccessfully to set up up the Flash Messages, but I'd like to avoid that if it is possible. Here's part of the code, it is mainly boilerplate</p>
  <pre><code>passport.use(
      new LocalStrategy((username, password, done) =&gt; {
          User.findOne({ username: username }, (err, user) =&gt; {
              if (err) {
                  return done(err);
              };
              if (!user) {
                  console.log(&quot;Incorrect username&quot;);
                  return done(null, false, { message: &quot;Incorrect username&quot; });
              }
              bcrypt.compare(password, user.password, (err, res) =&gt; {
                  if (res) {
                      // passwords match! log user in
                      console.log(&quot;Si pudiste logearte!!&quot;);
                      return done(null, user)
                  } else {
                      // passwords do not match!
                      console.log(&quot;Incorrect password&quot;);
                      return done(null, false, { message: &quot;Incorrect password&quot; })
                  }
              })
          });
      })
  );
  </code></pre>
  <pre><code>router.post(
      &quot;/log-in&quot;,
      passport.authenticate(&quot;local&quot;, {
          failureFlash: false,
          successRedirect: &quot;/&quot;,
          failureRedirect: &quot;/log-in&quot;
  
      })
  );
  </code></pre>