15088: Handles browser navigation during link account ops
[arvados-workbench2.git] / src / index.tsx
index 9f9b27ca912809f4730435382214a8d5ced02eeb..014627a9b2ea06e089e2e0bf7e902b51e29ce4f0 100644 (file)
@@ -64,6 +64,9 @@ import { loadFileViewersConfig } from '~/store/file-viewers/file-viewers-actions
 import { collectionAdminActionSet } from '~/views-components/context-menu/action-sets/collection-admin-action-set';
 import { processResourceAdminActionSet } from '~/views-components/context-menu/action-sets/process-resource-admin-action-set';
 import { projectAdminActionSet } from '~/views-components/context-menu/action-sets/project-admin-action-set';
+import { ACCOUNT_LINK_STATUS_KEY } from '~/services/link-account-service/link-account-service';
+import { cancelLinking } from '~/store/link-account-panel/link-account-panel-actions';
+import { matchTokenRoute } from '~/routes/routes';
 
 console.log(`Starting arvados [${getBuildInfo()}]`);
 
@@ -108,6 +111,13 @@ fetchConfig()
         });
         const store = configureStore(history, services);
 
+        // Cancel any link account ops in progess unless the user has
+        // just logged in or there has been a successful link operation
+        const data = sessionStorage.getItem(ACCOUNT_LINK_STATUS_KEY);
+        if (!matchTokenRoute(history.location.pathname) && data === null) {
+            store.dispatch<any>(cancelLinking());
+        }
+
         store.subscribe(initListener(history, store, services, config));
         store.dispatch(initAuth(config));
         store.dispatch(setBuildInfo());