title: Passport Authentication immediately after New User Registration
body: <p>I'm trying to authenticate and login a user immediately after submitting a POST on the <code>/register</code> form. Ideally, I would like users to be able to register and then be redirected immediately to the dashboard without having to enter their credentials again. </p>
  
  <p>My server is using Passport 0.1.17 with the local strategy configured to use email address and password for login. The current code is:</p>
  
  <pre><code>app.post('/register', function(req, res) {
  
    // attach POST to new User variable
    var registerUser = new User({ email: req.body.email, password: req.body.password, name: req.body.name });
  
    // save registerUser Mongo
    registerUser.save(function(err) {
      if(err) {
        console.log(err);
      } else {
        console.log('registerUser: ' + registerUser.email + " saved.");
      }
    });
  
    // here is where I am trying to authenticate and then redirect
    passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }),
    res.redirect('/dashboard');
    });
  </code></pre>
  
  <p>How would I refactor this code to save the new user, then authenticate and finally redirect to the dashboard?</p>
  
  <p>Thanks in advance!</p>