title: Passport Authentication in Nodejs
body: <p>Below is the Code that i'm working on but i'm getting errors while executing.
  Please help me in creating routes for both login and register forms which are on the same page.
  When I'm submitting the registration form with this code, I'm getting an error which says "Bad request"</p>
  
  <pre><code>var express = require ('express');
  var app = express();
  var path= require('path');
  var bodyParser = require('body-parser');
  var mongoose = require("mongoose");
  var nodemailer = require('nodemailer');
  var transporter = nodemailer.createTransport();
  var smtpTransport = require('nodemailer-smtp-transport');
  var passport = require('passport');
  var LocalStrategy = require('passport-local');
  var passportLocalMongoose = require('passport-local-mongoose');
  var User = require('./models/user');
  
  
  app.set('port',  process.env.PORT || 3000);
  app.use(bodyParser.json()); // support json encoded bodies
  app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
  
  app.use(express.static(path.join(__dirname, 'public')));
  app.set("view engine", "ejs");
  app.use(require('express-session')({
    secret: 'Working on enroll Medicare',
    resave: false,
    saveUninitialized: false
  }));
  app.use(passport.initialize());
  app.use(passport.session());
  
  passport.use(new LocalStrategy(User.authenticate()));
  passport.serializeUser(User.serializeUser());
  passport.deserializeUser(User.deserializeUser());
  
  mongoose.connect("mongodb://localhost/registration");
  app.post('/login-register.html', function(req,res)
  {
              var username = req.body.usernameregister;
              var email = req.body.emailregister;
              var password1 = req.body.password1register;
              var password2 = req.body.password2register;
          password1, password2: password2}
          User.register(new User({username: username, email: email}), password1, function(err, user){
            if(err){
              console.log(err);
              return res.render('error');
            }
            passport.authenticate('local')(req, res, function(){
                res.redirect("/secret");
            });
          });
  });
  </code></pre>
  
  <p>login page</p>
  
  <pre><code> app.post("/login-register.html", passport.authenticate('local', {
    succesRedirect: "/secret",
     failureRedirect: "/error"
   }), function(req, res){ });
  </code></pre>