Answer the question
In order to leave comments, you need to log in
Why does req.isAuthenticated() return false?
Hey! I have a node site using passportjs and express c postgresql database.
I have middleware for user sessions
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'});
}
};
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
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question