{"action":"created","issue":{"url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/171","repository_url":"https://api.github.com/repos/choonkending/react-webpack-node","labels_url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/171/labels{/name}","comments_url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/171/comments","events_url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/171/events","html_url":"https://github.com/choonkending/react-webpack-node/issues/171","id":140512030,"number":171,"title":"fetchComponentDataBeforeRender doesn't get access to session","user":{"login":"Epochi","id":13718394,"avatar_url":"https://avatars.githubusercontent.com/u/13718394?v=3","gravatar_id":"","url":"https://api.github.com/users/Epochi","html_url":"https://github.com/Epochi","followers_url":"https://api.github.com/users/Epochi/followers","following_url":"https://api.github.com/users/Epochi/following{/other_user}","gists_url":"https://api.github.com/users/Epochi/gists{/gist_id}","starred_url":"https://api.github.com/users/Epochi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Epochi/subscriptions","organizations_url":"https://api.github.com/users/Epochi/orgs","repos_url":"https://api.github.com/users/Epochi/repos","events_url":"https://api.github.com/users/Epochi/events{/privacy}","received_events_url":"https://api.github.com/users/Epochi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-03-13T18:08:25Z","updated_at":"2016-03-22T02:11:31Z","closed_at":null,"body":"Hey,\r\n\r\nIf user is already logged in and coming to the site, I'm unable to get user session data when using this\r\n\r\napp/Containers/Votes.jsx\r\n```\r\nclass Vote extends Component {\r\n....\r\n  static need = [\r\n    fetchTopics\r\n  ]\r\n...\r\n}\r\n```\r\nto call \r\nserver/config/routes.js\r\n\r\n`app.get('/topic', topics.all);`\r\n\r\n\r\nserver/controllers/topics.js\r\n```\r\nexports.all = function(req, res) {\r\n   console.log(req.user) //returns undefined\r\n   console.log(req) //returns shows empty passport object\r\n};\r\n\r\n```\r\n\r\n\r\nI think it's because of fetchComponentDataBeforeRender, it dispatches the action from itself and not from the component, so it doesn't pass the user. Because I can see that passport deserealizing the user before the promise is called  and these console logs\r\n\r\n```\r\n'app.get('/topic', fiunction(req,res){\r\nconsole.log(req.protocol + '://' + req.get('host') + req.originalUrl); \r\n//returns http://localhost:8080/top\r\n})\r\n  app.get('*', function (req, res, next) {\r\n   //  this fires before /topic as it should\r\n   // req.user returns the user\r\n   // console.log(req.protocol + '://' + req.get('host') + req.originalUrl); //returns https://www.myaddress.com/\r\n    App.default(req, res);\r\n  });\r\n```\r\n\r\n\r\nIs there any way to see the session object in this situation?\r\n\r\nUltimately my goal is to detect if the user is logged in and if he is, perform topics query and check which topics he has already voted on, to change the color of upvote arrow. Which I'm able to do if calling fetchTopics from componentsWillMount() inside of Vote.jsx"},"comment":{"url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/comments/199585748","html_url":"https://github.com/choonkending/react-webpack-node/issues/171#issuecomment-199585748","issue_url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/171","id":199585748,"user":{"login":"Epochi","id":13718394,"avatar_url":"https://avatars.githubusercontent.com/u/13718394?v=3","gravatar_id":"","url":"https://api.github.com/users/Epochi","html_url":"https://github.com/Epochi","followers_url":"https://api.github.com/users/Epochi/followers","following_url":"https://api.github.com/users/Epochi/following{/other_user}","gists_url":"https://api.github.com/users/Epochi/gists{/gist_id}","starred_url":"https://api.github.com/users/Epochi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Epochi/subscriptions","organizations_url":"https://api.github.com/users/Epochi/orgs","repos_url":"https://api.github.com/users/Epochi/repos","events_url":"https://api.github.com/users/Epochi/events{/privacy}","received_events_url":"https://api.github.com/users/Epochi/received_events","type":"User","site_admin":false},"created_at":"2016-03-22T02:11:31Z","updated_at":"2016-03-22T02:11:31Z","body":"@choonkending I think I have found a solution! \r\n\r\ninside  [app/server.jsx](https://github.com/choonkending/react-webpack-node/blob/master/app/server.jsx#L58)\r\n\r\n```\r\n */\r\nexport default function render(req, res) {\r\n    const history = createMemoryHistory();\r\n    const authenticated = req.isAuthenticated();\r\n    const store = configureStore({\r\n      user: {\r\n        authenticated: authenticated,\r\n        isWaiting: false,\r\n        message: '',\r\n        isLogin: true\r\n      }\r\n    }, history);\r\n    \r\n    if(authenticated){\r\n    \r\n    const requestInterceptor = axios.interceptors.request.use(function (config) {\r\n          config.headers['cookie'] = req.headers.cookie;\r\n          return config;\r\n       }, function (error) {\r\n          return Promise.reject(error);\r\n    });\r\n    const responseInterceptor = axios.interceptors.response.use(function (response) {\r\n            axios.interceptors.request.eject(requestInterceptor);\r\n            axios.interceptors.response.eject(responseInterceptor);\r\n            return response;\r\n           }, function (error) {\r\n            axios.interceptors.request.eject(requestInterceptor);\r\n            axios.interceptors.response.eject(responseInterceptor);\r\n            return Promise.reject(error);\r\n      });  \r\n    }\r\n      \r\n    const routes = createRoutes(store);\r\n\r\n  match({ routes, location: req.url }, (error, redirectLocation, renderProps) => {\r\n    ...\r\n  });\r\n}\r\n```\r\n\r\nAs I understand the render function gets called only once, because later on all routing is handled solely by react-router. So axios creates interceptor only for requests that are called by statics need and on response the interceptors destroy themselves. (not sure if it would work if there's more static functions, because they would delete themselves after first response, maybe it would be better to add it inside another .then after fetchComponentDataBeforeRender )\r\n\r\nSo basically I'm just sending users cookie to the server again \r\n\r\nAs far as I can tell there is no way for users to access this file and/or function, so this should be safe?\r\n\r\n"}}