Приветствую!
Помоги мне понять как отлавливаются ошибки и прокидываются дальше использую пасспорт библиотеку и флеш коннект
var express = require('express'),
router = express.Router(),
passport = require('../auth'),
Render = require('../render'),
render = Render.render;
var flash = require('connect-flash');
// middleware that is specific to this router
router
.use(flash())
.use(passport.initialize())
.use(passport.session());
router.use(function(req, res, next) {
res.locals.success_msg = req.flash('success_msg');
res.locals.error_msg = req.flash('error_msg');
res.locals.error = req.flash('error');
next();
});
// Global routes
// Auth local
router.post('/admin/login/', passport.authenticate('local',
{ failureRedirect: '/admin/login/', successRedirect: '/admin/', failureFlash: true }));
router.get('/admin/login/', function(req, res) {
console.log(req);
render(req, res, {
view: 'admin-login',
title: 'Панель управления - Вход',
meta: {
description: 'Page description',
og: {
url: 'https://site.com',
siteName: 'Site name'
}
},
})
})
вот сам паспорт
// auth.js
var passport = require('passport');
var User = require('./model/user');
var LocalStrategy = require('passport-local').Strategy;
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() {
User.findOne({
'username': username,
}, function(err, user) {
if (err) {
return done(err, { message: 'Houston we have a some problem' });
}
if (!user) {
return done(null, false, { message: 'Incorrect name.' });
}
if (user.password != password) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
});
});
}));
module.exports = passport;