node.js - Passport.js / Express.js Creating New Session on Every Network Request -


i have working login function authenticates , saves. however, express never remembers old session, creates new 1 every network request.

evidently, passport exceedingly sensitive order express middleware initialized. (example: https://www.airpair.com/express/posts/expressjs-and-passportjs-sessions-deep-dive). checked config against number of examples , rearranged if help, hasn't moved bug. either isn't issue or haven't found config holy grail yet. here's current config:

express config

app.engine('html', require('ejs').renderfile); app.set('view engine', 'html'); app.use(express.static(path.join(config.root, '/views'))); app.set('views', config.root + '/views'); var sessionopts = {     saveuninitialized: true,     resave: false,     store: new redisstore({         host: 'localhost',         port: 6379     }),     secret: 'keyboard',     cookie: {         httponly: true,         maxage: 1000     } } app.use(bodyparser.json()); app.use(bodyparser.urlencoded({     extended: false })); app.use(cookieparser('keyboard')); app.use(session(sessionopts)); app.use(passport.initialize()); app.use(passport.session()); app.use(cors()); require('./routes/router.js')(app, passport); 

passport config

 passport.use('local-login', new localstrategy({     usernamefield: 'email',     passwordfield: 'password',     passreqtocallback: true }, function(req, username, password, done) {     client.hgetall(username, function(err, reply) {         if (err) {             return done(err);         }         if (!reply) {             return done(null, false, {                 message: 'incorrect username.'             })         }         if (reply.password !== password) {             return done(null, false, {                 message: 'incorrect password.'             })         }         return done(null, reply)     }) })); 

does passport need handholding redis? redis sessions stored in 'sess' folder key so: sess:rhodmak2v2wdnlglv5j1b6rc. of tutorials i've found have been mongo i'm not sure if need somehow include session key when trying up. within session entry, it's stored in standard cookie form passport though: req.session.passport.user

is there way see happening inside of passport initialize? on subsequent requests supposed this: "the general passport middleware setup (passport.initialize) invoked on request, finds passport.user attached session. if doesn't (user not yet authenticated) creates req.passport.user = {}." see 'subsequent authenticated requests flow' - http://toon.io/understanding-passportjs-authentication-flow/ suspect problem lies @ step, nice able see inside of it.

some interesting tidbits:

  • passport has never once called deserializeuser. assume it's never
    reached point.
  • i have checked other stackoverflow questions problem, none of solutions worked me.
  • i've checked see if new sessions generated static resources not. it's intentional server requests. on pages without them, no new sessions made.
  • all sessions have either populated or empty req.session.passport property.

your session id might different every request because have cookie set expire after 1 second. cookie.maxage here in ms:

cookie: {     httponly: true,     maxage: 1000 } 

edit: have nag storing passwords in plaintext. don't ;)


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -