Set document title on navigation to url path, refs #19369
[arvados-workbench2.git] / src / store / auth / auth-middleware.ts
index 6eef5e5e16a59cd74d826dc3c32a09b6215894c4..0d08405ae11e87f329553e236e4550c0720a6fd6 100644 (file)
@@ -4,12 +4,12 @@
 
 import { Middleware } from "redux";
 import { authActions, } from "./auth-action";
-import { ServiceRepository, setAuthorizationHeader, removeAuthorizationHeader } from "~/services/services";
-import { initSessions } from "~/store/auth/auth-action-session";
-import { User } from "~/models/user";
-import { RootState } from '~/store/store';
-import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
-import { WORKBENCH_LOADING_SCREEN } from '~/store/workbench/workbench-actions';
+import { ServiceRepository, setAuthorizationHeader, removeAuthorizationHeader } from "services/services";
+import { initSessions } from "store/auth/auth-action-session";
+import { User } from "models/user";
+import { RootState } from 'store/store';
+import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
+import { WORKBENCH_LOADING_SCREEN } from 'store/workbench/workbench-actions';
 
 export const authMiddleware = (services: ServiceRepository): Middleware => store => next => action => {
     // Middleware to update external state (local storage, window
@@ -44,7 +44,7 @@ export const authMiddleware = (services: ServiceRepository): Middleware => store
                 // want to either add support for displaying/signing user
                 // agreements or get rid of self-activation.
                 // For more details, see:
-                // https://doc.arvados.org/master/admin/user-management.html
+                // https://doc.arvados.org/main/admin/user-management.html
 
                 store.dispatch(progressIndicatorActions.START_WORKING(WORKBENCH_LOADING_SCREEN));
                 services.userService.activate(user.uuid).then((user: User) => {
@@ -56,19 +56,20 @@ export const authMiddleware = (services: ServiceRepository): Middleware => store
             }
         },
         SET_CONFIG: ({ config }) => {
-            document.title = `Arvados Workbench (${config.uuidPrefix})`;
+            document.title = `Arvados (${config.uuidPrefix})`;
             next(action);
         },
-        LOGOUT: ({ deleteLinkData }) => {
+        LOGOUT: ({ deleteLinkData, preservePath }) => {
             next(action);
             if (deleteLinkData) {
                 services.linkAccountService.removeAccountToLink();
             }
+            const token = services.authService.getApiToken();
             services.authService.removeApiToken();
             services.authService.removeSessions();
             services.authService.removeUser();
             removeAuthorizationHeader(services);
-            services.authService.logout();
+            services.authService.logout(token || '', preservePath);
         },
         default: () => next(action)
     });