{"action":"created","issue":{"url":"https://api.github.com/repos/jaredhanson/passport/issues/452","labels_url":"https://api.github.com/repos/jaredhanson/passport/issues/452/labels{/name}","comments_url":"https://api.github.com/repos/jaredhanson/passport/issues/452/comments","events_url":"https://api.github.com/repos/jaredhanson/passport/issues/452/events","html_url":"https://github.com/jaredhanson/passport/issues/452","id":125601832,"number":452,"title":"passport is empty in session but has user in sessionStore","user":{"login":"bogas04","id":6177621,"avatar_url":"https://avatars.githubusercontent.com/u/6177621?v=3","gravatar_id":"","url":"https://api.github.com/users/bogas04","html_url":"https://github.com/bogas04","followers_url":"https://api.github.com/users/bogas04/followers","following_url":"https://api.github.com/users/bogas04/following{/other_user}","gists_url":"https://api.github.com/users/bogas04/gists{/gist_id}","starred_url":"https://api.github.com/users/bogas04/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bogas04/subscriptions","organizations_url":"https://api.github.com/users/bogas04/orgs","repos_url":"https://api.github.com/users/bogas04/repos","events_url":"https://api.github.com/users/bogas04/events{/privacy}","received_events_url":"https://api.github.com/users/bogas04/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-08T12:22:51Z","updated_at":"2016-01-09T10:34:22Z","closed_at":null,"body":"I've spent 4 hours scrolling through all SO posts about req.isAuthenticated() giving false always and then realizing that my `session.passport` lacks `user` itself and then figuring out that it appears in `sessionStore` once (I am using MemoryStore for now) and on second request it disappears, god knows why.\r\n\r\nPlease help me out.\r\n\r\n```javascript\r\nimport express from 'express';\r\nimport passport from 'passport';\r\nimport bodyParser from 'body-parser';\r\nimport constants from '../constants';\r\nconst app = express();\r\n\r\napp.use('/', express.static(__dirname + '/../client'));\r\n\r\n// Config\r\napp.use(bodyParser.urlencoded({ extended: false }));\r\napp.use(bodyParser.json({ limit: '25mb' }));\r\napp.use(require('express-session')({ \r\n  secret: 'yolo 123',\r\n  resave: true,\r\n  saveUninitialized: false,\r\n  cookie: { maxAge : 24*60*60*1000 }, \r\n}));\r\napp.use(passport.initialize());\r\napp.use(passport.session());\r\npassport.use(require('./passport-local'));\r\n\r\napp.get('/test', (req, res) => { \r\n  console.log(req.sessionStore, req.sessionID, req.session);\r\n  res.status(200).end(req.isAuthenticated() ? 'logged in': 'logged out');\r\n});\r\n\r\napp.post('/login', passport.authenticate('local'), (req, res) => {\r\n  let user = req.user.toJSON();\r\n  delete user.password;\r\n  res.status(200).json({ user })\r\n});\r\n...\r\n```\r\n\r\n./passport-local.js\r\n\r\n```javascript\r\nimport { Strategy } from 'passport-local';\r\nimport constants from '../constants';\r\nimport passport from 'passport';\r\nimport { User } from './db';\r\n\r\npassport.serializeUser((user, done) => done(null, user.id));\r\n\r\npassport.deserializeUser((user, done) => (\r\n  User.where({ id: user.id })\r\n  .fetch()\r\n  .then(u => done(null, u))\r\n));\r\n\r\nmodule.exports = new Strategy({ usernameField: 'username', passwordField: 'password' }, (username, password, done) => (\r\n  User.where({ username }).fetch()\r\n  .then(user => {\r\n    if(user) {\r\n      if (!password.compare(password, user.toJSON().password)) {\r\n        return done(null, false, { message: 'Incorrect password.' });\r\n      } else {\r\n        return done(null, user);\r\n      }\r\n    } else {\r\n      return done(null, false, { message: 'Incorrect username.' });\r\n    }\r\n  })\r\n  .catch(console.log)\r\n```\r\n\r\nFlow:\r\nLogin -> I receive user object with correct details from DB -> I visit `/test`\r\n```\r\nGET /test\r\nMemoryStore {\r\n  sessions: { N6YkV5_LIZRBTDcXDPMhgNSRRxtbZDIX: '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2016-01-09T12:09:21.366Z\",\"httpOnly\":true,\"path\":\"/\"},\"passport\":{\"user\":\"2\"}}' },\r\n  generate: [Function],\r\n  _events: { disconnect: [Function], connect: [Function] },\r\n  _eventsCount: 2 } 'N6YkV5_LIZRBTDcXDPMhgNSRRxtbZDIX' Session {\r\n  cookie: \r\n   { path: '/',\r\n     _expires: Sat Jan 09 2016 17:39:21 GMT+0530 (IST),\r\n     originalMaxAge: 86400000,\r\n     httpOnly: true },\r\n  passport: {} }\r\n```\r\n\r\nI revisit `/test`\r\n```\r\nGET /test\r\nMemoryStore {\r\n  sessions: { N6YkV5_LIZRBTDcXDPMhgNSRRxtbZDIX: '{\"cookie\":{\"originalMaxAge\":86400000,\"expires\":\"2016-01-09T12:09:24.179Z\",\"httpOnly\":true,\"path\":\"/\"},\"passport\":{}}' },\r\n  generate: [Function],\r\n  _events: { disconnect: [Function], connect: [Function] },\r\n  _eventsCount: 2 } 'N6YkV5_LIZRBTDcXDPMhgNSRRxtbZDIX' Session {\r\n  cookie: \r\n   { path: '/',\r\n     _expires: Sat Jan 09 2016 17:39:24 GMT+0530 (IST),\r\n     originalMaxAge: 86400000,\r\n     httpOnly: true },\r\n  passport: {} }\r\n```\r\n* Why is MemoryStore having `{user:2}` (that is the id) but not req.session on first request to `/test`\r\n* Why does it disappear in second request? \r\n\r\n**EDIT**: Just used database (postgres) for session store, exact same behaviour. What piece of code is making an update entry on the `passport: {}` in session store and thus emptying it?\r\n\r\n**EDIT2**: I'm adding/removing user to/from session myself in my login and logout routes for now, and they are persistent. I guess this has to do with passport getting confused or something like that. "},"comment":{"url":"https://api.github.com/repos/jaredhanson/passport/issues/comments/170223156","html_url":"https://github.com/jaredhanson/passport/issues/452#issuecomment-170223156","issue_url":"https://api.github.com/repos/jaredhanson/passport/issues/452","id":170223156,"user":{"login":"bogas04","id":6177621,"avatar_url":"https://avatars.githubusercontent.com/u/6177621?v=3","gravatar_id":"","url":"https://api.github.com/users/bogas04","html_url":"https://github.com/bogas04","followers_url":"https://api.github.com/users/bogas04/followers","following_url":"https://api.github.com/users/bogas04/following{/other_user}","gists_url":"https://api.github.com/users/bogas04/gists{/gist_id}","starred_url":"https://api.github.com/users/bogas04/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bogas04/subscriptions","organizations_url":"https://api.github.com/users/bogas04/orgs","repos_url":"https://api.github.com/users/bogas04/repos","events_url":"https://api.github.com/users/bogas04/events{/privacy}","received_events_url":"https://api.github.com/users/bogas04/received_events","type":"User","site_admin":false},"created_at":"2016-01-09T10:34:22Z","updated_at":"2016-01-09T10:34:22Z","body":"\r\n**NOTE** : Passport is still not filling req.user, I am manually adding user to session at login and removing on logout, so I guess the issue is still valid."}}