From: Peter Amstutz Date: Thu, 14 Nov 2019 15:07:21 +0000 (-0500) Subject: 15803: Move LOGOUT side effects to middleware X-Git-Tag: 2.0.0~26^2~9 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/db4b8c25a0a3418df5645060ccfa9406d20fce62 15803: Move LOGOUT side effects to middleware --- diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts index e220acb2..5fbfce48 100644 --- a/src/store/auth/auth-action.ts +++ b/src/store/auth/auth-action.ts @@ -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; diff --git a/src/store/auth/auth-middleware.ts b/src/store/auth/auth-middleware.ts index c96b1e02..d37ef08c 100644 --- a/src/store/auth/auth-middleware.ts +++ b/src/store/auth/auth-middleware.ts @@ -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) }); };