How do I output a more detailed log of the error in the Express (Passport)?

Try using Express to write a simple system of registration/authorization using Passport, but ran into an error and don't know where to go. When trying to send form data in Mongo database to get messages error "Missing credentials" - joxi.ru/8Anok4bfjEG4Gr
What he doesn't like I do not understand. What are the ways to bring a more detailed error log?

app.js

app.get('/register', function(req, res, next) {
 var messages = req.flash('error');
 Res. render('register.hbs', {
 title: 'Registration',
 messages: messages, 
 hasErrors: messages.length > 0
});
});

app.post('/register', passport.authenticate('local.signup', {
 successRedirect: 'start',
 failureRedirect: 'register',
 failureFlash: true
}));


passport.js

var passport = require('passport');
var User = require('../models/user');
var LocalStrategy = require('passport-local').Strategy;


passport.serializeUser(function(user, done) {
 done(null, user.id);
});

passport.deserializeUser(function(id, done) {
 User.findById(id, function(err, user) {
 done(err, user);
});
});

passport.use('local.signup', new LocalStrategy({
 usernameField: 'username',
 password: 'password',
 passRecToCallback: true
}, function(req, username, password, done) {
 User.findOne({username: 'username'}, function(err, user) {
 if(err) {
 return done(err);
}
 if(user) {
 return done(null, false, {message: 'This username is busy'});
}
 var newUser = new User();
 newUser.username = username;
 newUser.password = newUser.encryptPassword(password);
 newUser.save(function(err, result) {
 if(err) {
 return done(err);
}
 return done(null, newUser);
});
 }); 
}
)
);




passport.use('local.signup', new LocalStrategy({
 usernameField: 'username',
 passwordField: 'password',
 passReqToCallback: true
}, function (req, username, password, done) {
 req.checkBody('username', 'Invalid username').notEmpty();
 req.checkBody('password', 'Invalid password').notEmpty().isLength({min:4});
 var errors = req.validationErrors();
 if (errors) {
 var messages = [];
 errors.forEach(function(error) {
messages.push(error.msg);
});
 return done(null, false, req.flash('error', messages));
}
 User.findOne({'username': username}, function (err, user) {
 if (err) {
 return done(err);
}
 if (user) {
 return done(null, false, {message: 'username is already in use.'});
}
 var newUser = new User();
 newUser.username = username;
 newUser.password = newUser.encryptPassword(password);
 newUser.save(function(err, result) {
 if (err) {
 return done(err);
}
 return done(null, newUser);
});
});
}));
June 10th 19 at 16:00
0 answer

Find more questions by tags MongoDBExpress.jsNode.js