{"action":"created","issue":{"url":"https://api.github.com/repos/jaredhanson/passport/issues/482","repository_url":"https://api.github.com/repos/jaredhanson/passport","labels_url":"https://api.github.com/repos/jaredhanson/passport/issues/482/labels{/name}","comments_url":"https://api.github.com/repos/jaredhanson/passport/issues/482/comments","events_url":"https://api.github.com/repos/jaredhanson/passport/issues/482/events","html_url":"https://github.com/jaredhanson/passport/issues/482","id":152464122,"number":482,"title":"`req.isAuthenticated()` returning false immediately after login","user":{"login":"jmeas","id":2322305,"avatar_url":"https://avatars.githubusercontent.com/u/2322305?v=3","gravatar_id":"","url":"https://api.github.com/users/jmeas","html_url":"https://github.com/jmeas","followers_url":"https://api.github.com/users/jmeas/followers","following_url":"https://api.github.com/users/jmeas/following{/other_user}","gists_url":"https://api.github.com/users/jmeas/gists{/gist_id}","starred_url":"https://api.github.com/users/jmeas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmeas/subscriptions","organizations_url":"https://api.github.com/users/jmeas/orgs","repos_url":"https://api.github.com/users/jmeas/repos","events_url":"https://api.github.com/users/jmeas/events{/privacy}","received_events_url":"https://api.github.com/users/jmeas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2016-05-02T00:08:52Z","updated_at":"2016-06-18T03:19:51Z","closed_at":null,"body":"[StackOverflow question here.](http://stackoverflow.com/questions/36975133/passport-js-isauthenticated-inconsistent-behavior-false-when-it-should-be-t)\r\n\r\nI've been fighting for quite awhile with this bug: immediately after the user authenticates with, say, Google, `req.isAuthenticated()` is returning false. I'm persisting sessions to a Postgres DB, which seems to be working fine. It's just the call to `isAuthenticated` which leads me to wonder if my Passport configuration might be wrong, or something.\r\n\r\nMy code for the callback looks like:\r\n\r\n```js\r\nconst redirects = {\r\n  successRedirect: '/success',\r\n  failureRedirect: '/failure'\r\n};\r\napp.get('/auth/google/callback', passport.authenticate('google', redirects));\r\n```\r\n\r\nMy very last middleware logs the value of `req.isAuthenticated()`. It logs `false` when Google redirects back to my page, but if the user manually refreshes then it returns `true`.\r\n\r\nHere are detailed logs of the logging in process:\r\n\r\n```sh\r\n# this is the first request to the login page. Not logged in yet.\r\n4:59:54 PM web.1 |  -----New request-----\r\n4:59:54 PM web.1 |  route: /login authenticated: false\r\n\r\n# they've clicked the link to `/login`, and are immediately forwarded to Google\r\n4:59:59 PM web.1 |  -----New request-----\r\n\r\n# they've granted across through Google; Google redirects back to app.\r\n# Using the Google profile, we get the user's account from the user account table\r\n5:00:06 PM web.1 |  -----New request-----\r\n5:00:06 PM web.1 |  about to fetch from DB\r\n5:00:07 PM web.1 |  retrieved user from DB\r\n\r\n# redirection to the success page...`authenticated` is false? It should now be true!\r\n5:00:07 PM web.1 |  -----New request-----\r\n5:00:07 PM web.1 |  route: /success authenticated: false\r\n\r\n# here's a manual refresh...now they're showing as authenticated\r\n5:05:34 PM web.1 |  successful deserialize\r\n5:05:34 PM web.1 |  -----New request-----\r\n5:05:34 PM web.1 |  route: /success authenticated: true\r\n```\r\n\r\nIt looks like `deserialize` isn't being called when Google redirects back to my app; could that be the source of the issue?\r\n\r\nSource code:\r\n\r\n- [Passport configuration](https://github.com/jmeas/finance-app/blob/google-sign-in/server/utils/configure-passport.js)\r\n- [Express app configuration](https://github.com/jmeas/finance-app/blob/google-sign-in/server/app.js)"},"comment":{"url":"https://api.github.com/repos/jaredhanson/passport/issues/comments/226918849","html_url":"https://github.com/jaredhanson/passport/issues/482#issuecomment-226918849","issue_url":"https://api.github.com/repos/jaredhanson/passport/issues/482","id":226918849,"user":{"login":"arzavj","id":1191939,"avatar_url":"https://avatars.githubusercontent.com/u/1191939?v=3","gravatar_id":"","url":"https://api.github.com/users/arzavj","html_url":"https://github.com/arzavj","followers_url":"https://api.github.com/users/arzavj/followers","following_url":"https://api.github.com/users/arzavj/following{/other_user}","gists_url":"https://api.github.com/users/arzavj/gists{/gist_id}","starred_url":"https://api.github.com/users/arzavj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arzavj/subscriptions","organizations_url":"https://api.github.com/users/arzavj/orgs","repos_url":"https://api.github.com/users/arzavj/repos","events_url":"https://api.github.com/users/arzavj/events{/privacy}","received_events_url":"https://api.github.com/users/arzavj/received_events","type":"User","site_admin":false},"created_at":"2016-06-18T03:19:51Z","updated_at":"2016-06-18T03:19:51Z","body":"Hey @jmeas! Curious to know if you figured it out, I'm running into the same issue. Thanks a bunch! "}}
{"actor":{"display_login":"arzavj"}}