{"action":"created","comment":{"url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments/54188987","id":54188987,"diff_hunk":"@@ -18,27 +24,117 @@ import { getSupportUser, getSupportToken } from 'state/support/selectors';\n  *\n  * @param {Object}  reduxStore  The global redux store instance\n  */\n-export default function( reduxStore ) {\n-\tconst user = new User();\n+class SupportUser {\n+\tconstructor() {\n+\t\tdebug( 'Support User is enabled in this environment' );\n \n-\t// Called when the support user token was updated in wpcom\n-\tconst onTokenChange = () => {\n-\t\tuser.fetch();\n-\t\tuserSettings.fetchSettings();\n+\t\tthis.reduxStoreReady = new Promise( ( resolve ) => {\n+\t\t\tthis.setReduxStore = ( reduxStore ) => resolve( reduxStore );\n+\t\t} );\n \t}\n \n-\t// Called when an API call fails due to a token error\n-\tconst onTokenError = ( error ) => {\n-\t\treduxStore.dispatch( supportUserRestore( error ) );\n+\tfetchToken( user, password ) {\n+\t\tdebug( 'Fetching support user token' );\n+\n+\t\treturn this.reduxStoreReady.then( ( reduxStore ) => {\n+\t\t\treduxStore.dispatch( supportUserTokenFetch( user ) );\n+\n+\t\t\tconst setToken = ( response ) => {\n+\t\t\t\tthis.rebootWithToken( response.username, response.token );\n+\t\t\t};\n+\n+\t\t\tconst errorFetchingToken = ( error ) => {\n+\t\t\t\treduxStore.dispatch( supportUserError( error.message ) );\n+\t\t\t};\n+\n+\t\t\treturn wpcom.fetchSupportUserToken( user, password )\n+\t\t\t\t.then( setToken )\n+\t\t\t\t.catch( errorFetchingToken );\n+\t\t} );\n \t}\n \n-\t// Follow any changes to the support token in the Redux store and\n-\t// update the wpcom API interceptor accordingly.\n-\treduxStore.subscribe( () => {\n-\t\tconst state = reduxStore.getState();\n+\t/**\n+\t * Reboot normally as the main user\n+\t */\n+\trebootNormally() {\n+\t\tdebug( 'Rebooting Calypso normally' );\n \n-\t\tif ( wpcom.setSupportUserToken( getSupportUser( state ), getSupportToken( state ) ) ) {\n-\t\t\tonTokenChange();\n+\t\tstore.remove( STORAGE_KEY );\n+\t\twindow.location.reload();\n+\t}\n+\n+\t/**\n+\t  * Reboot Calypso as the support user\n+\t  * @param  {string} user  The support user's username\n+\t  * @param  {string} token The support token\n+\t  */\n+\trebootWithToken( user, token ) {\n+\t\tdebug( 'Rebooting Calypso with support user' );\n+\n+\t\tstore.set( STORAGE_KEY, { user, token } );\n+\t\twindow.location.reload();","path":"client/lib/user/support-user-interop.js","position":90,"original_position":90,"commit_id":"1f74723ca88fcebaecf0c0ea839acc476b6f60c5","original_commit_id":"1f74723ca88fcebaecf0c0ea839acc476b6f60c5","user":{"login":"gwwar","id":1270189,"avatar_url":"https://avatars.githubusercontent.com/u/1270189?v=3","gravatar_id":"","url":"https://api.github.com/users/gwwar","html_url":"https://github.com/gwwar","followers_url":"https://api.github.com/users/gwwar/followers","following_url":"https://api.github.com/users/gwwar/following{/other_user}","gists_url":"https://api.github.com/users/gwwar/gists{/gist_id}","starred_url":"https://api.github.com/users/gwwar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwwar/subscriptions","organizations_url":"https://api.github.com/users/gwwar/orgs","repos_url":"https://api.github.com/users/gwwar/repos","events_url":"https://api.github.com/users/gwwar/events{/privacy}","received_events_url":"https://api.github.com/users/gwwar/received_events","type":"User","site_admin":false},"body":"Good idea. @aduth can you think of any other cases we might run into besides login/logout/switch user where current user id is updated?","created_at":"2016-02-26T00:32:51Z","updated_at":"2016-02-26T00:32:51Z","html_url":"https://github.com/Automattic/wp-calypso/pull/3492#discussion_r54188987","pull_request_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3492","_links":{"self":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments/54188987"},"html":{"href":"https://github.com/Automattic/wp-calypso/pull/3492#discussion_r54188987"},"pull_request":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3492"}}},"pull_request":{"url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3492","id":60295605,"html_url":"https://github.com/Automattic/wp-calypso/pull/3492","diff_url":"https://github.com/Automattic/wp-calypso/pull/3492.diff","patch_url":"https://github.com/Automattic/wp-calypso/pull/3492.patch","issue_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/3492","number":3492,"state":"open","locked":false,"title":"Support User: Perform a complete page refresh when activating","user":{"login":"jordwest","id":416133,"avatar_url":"https://avatars.githubusercontent.com/u/416133?v=3","gravatar_id":"","url":"https://api.github.com/users/jordwest","html_url":"https://github.com/jordwest","followers_url":"https://api.github.com/users/jordwest/followers","following_url":"https://api.github.com/users/jordwest/following{/other_user}","gists_url":"https://api.github.com/users/jordwest/gists{/gist_id}","starred_url":"https://api.github.com/users/jordwest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordwest/subscriptions","organizations_url":"https://api.github.com/users/jordwest/orgs","repos_url":"https://api.github.com/users/jordwest/repos","events_url":"https://api.github.com/users/jordwest/events{/privacy}","received_events_url":"https://api.github.com/users/jordwest/received_events","type":"User","site_admin":false},"body":"This performs a full page reload when a support user token is activated/deactivated to ensure all user data is fully refreshed. Between refreshes, the support token is stored in localstorage using the **store** module. On the following boot of Calypso, the User initialization sequence is intercepted before the original user is loaded, to ensure none of the original user's data is loaded.\r\n\r\nAdditionally, an error message is now displayed when an error occurs while fetching a token.\r\n\r\nNo other functionality has been changed; the testing procedure is the same (ref: p4TIVU-2OW-p2)\r\n\r\nA few notes for review:\r\n - The Redux store wasn't an option for storing the support token, as we need to check for the token at the earliest point during **User** module initialization, before the Redux store is initialized.\r\n - Attempts to use **localforage** also caused issues due to its async API and the synchronous nature of the boot process - see #3556\r\n\r\nFixes #3029, fixes #3067, fixes #3068 as well as various other non-reported issues (ref p4TIVU-2OW-p2)\r\n\r\ncc @dllh @gwwar @mtias ","created_at":"2016-02-23T06:47:53Z","updated_at":"2016-02-26T00:32:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bfcde8b5075fdbe2d949a52c62dbb435bba67303","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3492/commits","review_comments_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3492/comments","review_comment_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/3492/comments","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/1f74723ca88fcebaecf0c0ea839acc476b6f60c5","head":{"label":"Automattic:update/support-user/full-refresh","ref":"update/support-user/full-refresh","sha":"1f74723ca88fcebaecf0c0ea839acc476b6f60c5","user":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"repo":{"id":45936895,"name":"wp-calypso","full_name":"Automattic/wp-calypso","owner":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Automattic/wp-calypso","description":"The new JavaScript- and API-powered WordPress.com","fork":false,"url":"https://api.github.com/repos/Automattic/wp-calypso","forks_url":"https://api.github.com/repos/Automattic/wp-calypso/forks","keys_url":"https://api.github.com/repos/Automattic/wp-calypso/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Automattic/wp-calypso/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Automattic/wp-calypso/teams","hooks_url":"https://api.github.com/repos/Automattic/wp-calypso/hooks","issue_events_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/events{/number}","events_url":"https://api.github.com/repos/Automattic/wp-calypso/events","assignees_url":"https://api.github.com/repos/Automattic/wp-calypso/assignees{/user}","branches_url":"https://api.github.com/repos/Automattic/wp-calypso/branches{/branch}","tags_url":"https://api.github.com/repos/Automattic/wp-calypso/tags","blobs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Automattic/wp-calypso/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/refs{/sha}","trees_url":"https://api.github.com/repos/Automattic/wp-calypso/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/{sha}","languages_url":"https://api.github.com/repos/Automattic/wp-calypso/languages","stargazers_url":"https://api.github.com/repos/Automattic/wp-calypso/stargazers","contributors_url":"https://api.github.com/repos/Automattic/wp-calypso/contributors","subscribers_url":"https://api.github.com/repos/Automattic/wp-calypso/subscribers","subscription_url":"https://api.github.com/repos/Automattic/wp-calypso/subscription","commits_url":"https://api.github.com/repos/Automattic/wp-calypso/commits{/sha}","git_commits_url":"https://api.github.com/repos/Automattic/wp-calypso/git/commits{/sha}","comments_url":"https://api.github.com/repos/Automattic/wp-calypso/comments{/number}","issue_comment_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/comments{/number}","contents_url":"https://api.github.com/repos/Automattic/wp-calypso/contents/{+path}","compare_url":"https://api.github.com/repos/Automattic/wp-calypso/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Automattic/wp-calypso/merges","archive_url":"https://api.github.com/repos/Automattic/wp-calypso/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Automattic/wp-calypso/downloads","issues_url":"https://api.github.com/repos/Automattic/wp-calypso/issues{/number}","pulls_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls{/number}","milestones_url":"https://api.github.com/repos/Automattic/wp-calypso/milestones{/number}","notifications_url":"https://api.github.com/repos/Automattic/wp-calypso/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Automattic/wp-calypso/labels{/name}","releases_url":"https://api.github.com/repos/Automattic/wp-calypso/releases{/id}","deployments_url":"https://api.github.com/repos/Automattic/wp-calypso/deployments","created_at":"2015-11-10T20:00:16Z","updated_at":"2016-02-25T23:29:33Z","pushed_at":"2016-02-25T23:59:44Z","git_url":"git://github.com/Automattic/wp-calypso.git","ssh_url":"git@github.com:Automattic/wp-calypso.git","clone_url":"https://github.com/Automattic/wp-calypso.git","svn_url":"https://github.com/Automattic/wp-calypso","homepage":"https://developer.wordpress.com/calypso/","size":56272,"stargazers_count":6871,"watchers_count":6871,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":793,"mirror_url":null,"open_issues_count":1226,"forks":793,"open_issues":1226,"watchers":6871,"default_branch":"master"}},"base":{"label":"Automattic:master","ref":"master","sha":"bef60469ae6afeb4e036ca3f848a6f9387a48e15","user":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"repo":{"id":45936895,"name":"wp-calypso","full_name":"Automattic/wp-calypso","owner":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Automattic/wp-calypso","description":"The new JavaScript- and API-powered WordPress.com","fork":false,"url":"https://api.github.com/repos/Automattic/wp-calypso","forks_url":"https://api.github.com/repos/Automattic/wp-calypso/forks","keys_url":"https://api.github.com/repos/Automattic/wp-calypso/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Automattic/wp-calypso/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Automattic/wp-calypso/teams","hooks_url":"https://api.github.com/repos/Automattic/wp-calypso/hooks","issue_events_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/events{/number}","events_url":"https://api.github.com/repos/Automattic/wp-calypso/events","assignees_url":"https://api.github.com/repos/Automattic/wp-calypso/assignees{/user}","branches_url":"https://api.github.com/repos/Automattic/wp-calypso/branches{/branch}","tags_url":"https://api.github.com/repos/Automattic/wp-calypso/tags","blobs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Automattic/wp-calypso/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/refs{/sha}","trees_url":"https://api.github.com/repos/Automattic/wp-calypso/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/{sha}","languages_url":"https://api.github.com/repos/Automattic/wp-calypso/languages","stargazers_url":"https://api.github.com/repos/Automattic/wp-calypso/stargazers","contributors_url":"https://api.github.com/repos/Automattic/wp-calypso/contributors","subscribers_url":"https://api.github.com/repos/Automattic/wp-calypso/subscribers","subscription_url":"https://api.github.com/repos/Automattic/wp-calypso/subscription","commits_url":"https://api.github.com/repos/Automattic/wp-calypso/commits{/sha}","git_commits_url":"https://api.github.com/repos/Automattic/wp-calypso/git/commits{/sha}","comments_url":"https://api.github.com/repos/Automattic/wp-calypso/comments{/number}","issue_comment_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/comments{/number}","contents_url":"https://api.github.com/repos/Automattic/wp-calypso/contents/{+path}","compare_url":"https://api.github.com/repos/Automattic/wp-calypso/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Automattic/wp-calypso/merges","archive_url":"https://api.github.com/repos/Automattic/wp-calypso/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Automattic/wp-calypso/downloads","issues_url":"https://api.github.com/repos/Automattic/wp-calypso/issues{/number}","pulls_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls{/number}","milestones_url":"https://api.github.com/repos/Automattic/wp-calypso/milestones{/number}","notifications_url":"https://api.github.com/repos/Automattic/wp-calypso/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Automattic/wp-calypso/labels{/name}","releases_url":"https://api.github.com/repos/Automattic/wp-calypso/releases{/id}","deployments_url":"https://api.github.com/repos/Automattic/wp-calypso/deployments","created_at":"2015-11-10T20:00:16Z","updated_at":"2016-02-25T23:29:33Z","pushed_at":"2016-02-25T23:59:44Z","git_url":"git://github.com/Automattic/wp-calypso.git","ssh_url":"git@github.com:Automattic/wp-calypso.git","clone_url":"https://github.com/Automattic/wp-calypso.git","svn_url":"https://github.com/Automattic/wp-calypso","homepage":"https://developer.wordpress.com/calypso/","size":56272,"stargazers_count":6871,"watchers_count":6871,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":793,"mirror_url":null,"open_issues_count":1226,"forks":793,"open_issues":1226,"watchers":6871,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3492"},"html":{"href":"https://github.com/Automattic/wp-calypso/pull/3492"},"issue":{"href":"https://api.github.com/repos/Automattic/wp-calypso/issues/3492"},"comments":{"href":"https://api.github.com/repos/Automattic/wp-calypso/issues/3492/comments"},"review_comments":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3492/comments"},"review_comment":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/3492/commits"},"statuses":{"href":"https://api.github.com/repos/Automattic/wp-calypso/statuses/1f74723ca88fcebaecf0c0ea839acc476b6f60c5"}}}}