title: Getting out of sync server response
body: <p>On a successful signup of a user I am currently seeing a mostly empty page with the text <code>undefined. Redirecting to /app</code> at the top.</p>
  
  <p>UPDATE:  I should also mention that after form submittal I am redirected to /users. So on /users I see the text mentioned above.</p>
  
  <p>I think it is because of the req.redirect call being within the user.save callback but I am not sure what the fix is.</p>
  
  <p>I am using mongoose for the ORM.</p>
  
  <pre><code>var User = require('../models/user');
  
  module.exports = function(app) {
  
    app.post('/users', function(req, res, next) {
      var user = new User({
        email:      req.body.email,
        password:   req.body.password
      });
  
      user.save(function(err) {
        if (err)
          res.send(412, {message: err});
        else
          req.login(user, function(err) {
            if (err !== undefined) return next(err);
            res.redirect('/app', {
              email: user.email,
              id:    user._id
            });
          });
      });
  
    });
  };
  </code></pre>