我有一些会话中间件
var session = require('express-session');
var config = require('config');
module.exports = session({
secret: config.secret,
resave: true,
saveUninitialized: true,
cookie: {
secure: false,
httpOnly : true,
maxAge : 30 * 24 * 60 * 60 * 1000 //30days
}
});
我还有授权用户的检查功能
var isAuthenticated = function (req, res, next) {
console.log('----------------' + req.isAuthenticated()) // true
if (req.isAuthenticated()) {
res.locals.login = req.isAuthenticated();
return next();
} else {
res.render('permissionDenied', {title: 'Permission denied'});
}
};
一切都好。现在我可以登录我的网站并显示授权用户的其他选项卡。但是当我使用商店pg进行会话时
var pgSession = require('connect-pg-simple')(session);
module.exports = session({
store: new pgSession({
conString : config.databaseString
}),
secret: 'SECRET',
resave: true, //don't save session if unmodified
saveUninitialized: true, // create session until something stored
expires: date.toUTCString(),
cookie: {
secure: false,
httpOnly : true,
maxAge : 30 * 24 * 60 * 60 * 1000 //30days
}
});
我的isAuthenticated()
总是返回false
!
请告诉我它可能是什么?