15803: Move LOGOUT side effects to middleware
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 14 Nov 2019 15:07:21 +0000 (10:07 -0500)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Thu, 14 Nov 2019 15:07:21 +0000 (10:07 -0500)
src/store/auth/auth-action.ts
src/store/auth/auth-middleware.ts

index e220acb2edd4c6eab3ae50b76dfea1bee2de6b7d..5fbfce48d8ec467de9345aeeba3ae713aaec3c5d 100644 (file)
@@ -16,7 +16,7 @@ import { createServices, setAuthorizationHeader, removeAuthorizationHeader } fro
 
 export const authActions = unionize({
     LOGIN: {},
-    LOGOUT: {},
+    LOGOUT: ofType<{ deleteLinkData: boolean }>(),
     CONFIG: ofType<{ config: Config }>(),
     INIT: ofType<{ user: User, token: string }>(),
     USER_DETAILS_REQUEST: {},
@@ -81,14 +81,7 @@ export const login = (uuidPrefix: string, homeCluster: string, loginCluster: str
     };
 
 export const logout = (deleteLinkData: boolean = false) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-    if (deleteLinkData) {
-        services.linkAccountService.removeAccountToLink();
-    }
-    services.authService.removeApiToken();
-    services.authService.removeUser();
-    removeAuthorizationHeader(services);
-    services.authService.logout();
-    dispatch(authActions.LOGOUT());
+    dispatch(authActions.LOGOUT({ deleteLinkData }));
 };
 
 export type AuthAction = UnionOf<typeof authActions>;
index c96b1e027ad3c5488d8819cdf118fec053859e7b..d37ef08c1e2a83a5252b70fb91edde3e8b2775e1 100644 (file)
@@ -38,6 +38,16 @@ export const authMiddleware = (services: ServiceRepository): Middleware => store
             document.title = `Arvados Workbench (${config.uuidPrefix})`;
             next(action);
         },
+       LOGOUT: ({deleteLinkData}) => {
+           next(action)            
+           if (deleteLinkData) {
+               services.linkAccountService.removeAccountToLink();
+           }
+           services.authService.removeApiToken();
+           services.authService.removeUser();
+           removeAuthorizationHeader(services);
+           services.authService.logout();          
+       },
         default: () => next(action)
     });
 };