From eb633efdb3fa8ecb0c2c6a5e35916585282436ea Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Mon, 8 Mar 2021 14:04:45 -0300 Subject: [PATCH] 16848: Resets extra cached token from the store when not valid anymore. This is to make the "Get API token" dialog default to the wb2's session token. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/store/auth/auth-action.ts | 5 ++++- src/store/auth/auth-reducer.ts | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts index 27558618..4f576fe4 100644 --- a/src/store/auth/auth-action.ts +++ b/src/store/auth/auth-action.ts @@ -23,6 +23,7 @@ export const authActions = unionize({ LOGOUT: ofType<{ deleteLinkData: boolean }>(), SET_CONFIG: ofType<{ config: Config }>(), SET_EXTRA_TOKEN: ofType<{ extraApiToken: string, extraApiTokenExpiration?: Date }>(), + RESET_EXTRA_TOKEN: {}, INIT_USER: ofType<{ user: User, token: string, tokenExpiration?: Date }>(), USER_DETAILS_REQUEST: {}, USER_DETAILS_SUCCESS: ofType(), @@ -112,7 +113,9 @@ export const getNewExtraToken = (reuseStored: boolean = false) => extraApiTokenExpiration: client.expiresAt ? new Date(client.expiresAt): undefined, })); return extraToken; - } catch (e) { } + } catch (e) { + dispatch(authActions.RESET_EXTRA_TOKEN()); + } } const user = getState().auth.user; const loginCluster = getState().auth.config.clusterConfig.Login.LoginCluster; diff --git a/src/store/auth/auth-reducer.ts b/src/store/auth/auth-reducer.ts index 7459b7ac..b29cf341 100644 --- a/src/store/auth/auth-reducer.ts +++ b/src/store/auth/auth-reducer.ts @@ -69,6 +69,8 @@ export const authReducer = (services: ServiceRepository) => (state = initialStat }), SET_EXTRA_TOKEN: ({ extraApiToken, extraApiTokenExpiration }) => ({ ...state, extraApiToken, extraApiTokenExpiration }), + RESET_EXTRA_TOKEN: () => + ({ ...state, extraApiToken: undefined, extraApiTokenExpiration: undefined }), INIT_USER: ({ user, token, tokenExpiration }) => ({ ...state, user, -- 2.30.2