E
E
ennet2016-04-06 14:28:39
JavaScript
ennet, 2016-04-06 14:28:39

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
    }
});

And also check if the user is logged in
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'});
    }
};

Everything is fine. Authorization works. sessions too. But when I wanted to use store for sessions
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() always returns false
, what could be the problem? thank!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
ennet, 2016-04-06
@ennet

changed to connet-redis and everything worked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question