{"action":"created","issue":{"url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/225","repository_url":"https://api.github.com/repos/choonkending/react-webpack-node","labels_url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/225/labels{/name}","comments_url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/225/comments","events_url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/225/events","html_url":"https://github.com/choonkending/react-webpack-node/pull/225","id":153828292,"number":225,"title":"authentication for server side render with axios interceptors.","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-05-09T17:32:10Z","updated_at":"2016-05-10T21:58:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/choonkending/react-webpack-node/pulls/225","html_url":"https://github.com/choonkending/react-webpack-node/pull/225","diff_url":"https://github.com/choonkending/react-webpack-node/pull/225.diff","patch_url":"https://github.com/choonkending/react-webpack-node/pull/225.patch"},"body":"Same as #184  but with significantly lower footprint\r\n\r\nBefore:\r\nif user comes to website with active session cookie and you call server side rendering through static needs methods, you don't see user session information, because the request is made from server to server.\r\n\r\nNow:\r\nwhen logged in user comes to website, we attach his cookie to all requests for the duration that preRenderMiddleware function renders all the promises, then we delete the interceptor.\r\n\r\nPros:\r\n\r\n- All server-side rendering can be done as if user was authenticated\r\n- We don't need to modify specific routes with express to get user specific data on server-side rendering, and we can just use static need methods that work for unauthenticated and authenticated users\r\n\r\nCons:\r\n\r\n- Relies on axios\r\n- If developer is using interceptors for something else, then they'd need to modify preRenderAuthentication.js because it deletes all other request interceptors on default axios instance\r\n"},"comment":{"url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/comments/218304355","html_url":"https://github.com/choonkending/react-webpack-node/pull/225#issuecomment-218304355","issue_url":"https://api.github.com/repos/choonkending/react-webpack-node/issues/225","id":218304355,"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-05-10T21:58:07Z","updated_at":"2016-05-10T21:58:07Z","body":"I have no idea why I deleted 'return config'! \r\n\r\nI did not use .eject(); because it sets the interceptor to null, instead of deleting it from the handlers array, and as the page gets reloaded that .handlers array keeps growing infinately.  \r\n\r\nI believe axios.interceptors.request.handlers array was how I noticed that cookies mix up with several requests happening at the same time, because every server prerender still uses same server-wide axios.\r\nIf we start preRenderMiddleware for one user and the second user starts it before the first one finishes, the both users will get data that's intended for second user.\r\n\r\nIt's amazing that you remembered #171!  I just walked a big circle around the same problem...\r\nI'll have to think about this problem some more, because it seems that custom axios instance still needs to be created for server to differentiate between users. \r\nI'm going to be away for a week from now, should I close the PR in the meantime and while I find a solution?\r\n\r\n"}}