0
錯誤發生在這裏(用戶==真!):護照本地不通過的消息
if (!user) {
console.log('---2');
return done(null, false, {message: 'Incorrect username.'});
}
路由器配置:
router.get('/', function(req, res, next) {
console.log('Message:'+req.flash('message'));
res.render('index', { title: 'Title', message: req.flash('message') });
});
router.post('/login', passport.authenticate('local', {
successRedirect: '/users/home',
failureRedirect: '/',
failureFlash: true
}));
控制檯日誌顯示,該消息到達空。但消息完全來自另一個功能(captcha檢查,使用相同的req.flash)。護照配置:
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
...
app.use(expressSession({secret: 'mySecretKey', resave: true, saveUninitialized: true }));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
var initPassport = require('./bin/auth/init-passport');
initPassport(passport);