title: I was able to authenticate an existing user but I couldn't create new user account? Here is my Code
body: <pre><code>//*********************This was to authenticate user*********************
  
  passport.serializeUser(function(user, done) {
  
        done(null, user);
  
  });
  
  passport.deserializeUser(function(user, done) {
  
         done(null, user);
  
  });
  
  passport.use(new LocalStrategy(function(username, password, done) {
  
       process.nextTick(function() {
  
          UserDetails.findOne({
  
            'username': username,
  
          }, function(err, user) {
  
                if (err) {
  
                    return done(err);
  
             }
  
              if (!user) {
  
                return done(null, false);
  
              }
  
              if (user.password != password) {
  
                   return done(null, false);
  
              }
  
              return done(null, user);
  
          });
  
        });
  
     }));
  
  //*********************This was to create new user*********************
  
  passport.use(new LocalStrategy(function(username, password, done) {
  
       process.nextTick(function() {
  
          UserDetails.findOne({
  
            'username': username,
  
          }, function(err, user) {
  
                if (err) {
  
                    return done(err);
  
             }
  
                if (!user) {
  
                    var newUser = new UserDetails({"username":newUsername, "password":newPassword});
  
                     newUser.save(function (err, newUser) {
                          if (err) 
                          {
                              return console.error(err);
                          }
                          console.log("Document Saved!");
                     });
                 return done(null, true);
              }
  
          });
  
        });
  
     }));
  </code></pre>
  
  <p>I have a <code>login.jade</code> file and <code>signup.jade</code>. So, when I want to sign in a user - if the user is in the database, it will authenticate the user successfully. But if the user does not exist it will insert a new user the database.</p>
  
  <p>So my question is what should I change in code so that the a new user would be able to create account using the signup page and and an existing user would be able use login?</p>
  
  <p>Thanks</p>