title: How to handle passport authentication response and show it to the user
body: <p>I'm authenticating my <strong>nodeJs</strong> app using passport local strategy. Everything is working fine. But how can I show the user appropriate message that he has entered <strong>invalid login credentials</strong>. My present code is just sending <strong>401 unauthorized error</strong> on screen.</p>
  
  <p>Here is my code</p>
  
  <pre><code>passport.use(new LocalStrategy(function(username, password, callback) {
      User.findOne({
          username : username
      }, function(err, user) {
          if (err) {
              return callback(err);
          }
  
          // No user found with that username
          if (!user) {
              return callback(null, false);
          }
  
          // Make sure the password is correct
          user.verifyPassword(password, function(err, isMatch) {
              if (err) {
                  return callback(err);
              }
  
              // Password did not match
              if (!isMatch) {
                  return callback(null, false);
              }
  
              // Success
              return callback(null, user);
          });
      });
  }));
  
  exports.isLocalAuthenticated = passport.authenticate('local', {
      session : true
  });
  
  router.post('/', authController.isLocalAuthenticated, function(req, res) {
      //here I want to show the error message to user
  
  });
  </code></pre>