From: Peter Amstutz Date: Mon, 13 May 2019 21:46:29 +0000 (-0400) Subject: 15064: Save/load homeCluster from localStorage. X-Git-Tag: 1.4.0~10^2~1 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/f35559bdd3569d836d084524ff64ed050e3c926e 15064: Save/load homeCluster from localStorage. Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts index cec0cef1..a80d89ba 100644 --- a/src/services/auth-service/auth-service.ts +++ b/src/services/auth-service/auth-service.ts @@ -20,6 +20,7 @@ export const USER_IS_ADMIN = 'isAdmin'; export const USER_IS_ACTIVE = 'isActive'; export const USER_USERNAME = 'username'; export const USER_PREFS = 'prefs'; +export const HOME_CLUSTER = 'homeCluster'; export interface UserDetailsResponse { email: string; @@ -42,6 +43,7 @@ export class AuthService { public saveApiToken(token: string) { localStorage.setItem(API_TOKEN_KEY, token); + localStorage.setItem(HOME_CLUSTER, token.split('/')[1].substr(0, 5)); } public removeApiToken() { @@ -52,6 +54,10 @@ export class AuthService { return localStorage.getItem(API_TOKEN_KEY) || undefined; } + public getHomeCluster() { + return localStorage.getItem(HOME_CLUSTER) || undefined; + } + public getUuid() { return localStorage.getItem(USER_UUID_KEY) || undefined; } diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts index c06e064e..7ebbbaa6 100644 --- a/src/store/auth/auth-action.ts +++ b/src/store/auth/auth-action.ts @@ -50,10 +50,12 @@ function removeAuthorizationHeader(client: AxiosInstance) { export const initAuth = (config: Config) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const user = services.authService.getUser(); const token = services.authService.getApiToken(); + const homeCluster = services.authService.getHomeCluster(); if (token) { setAuthorizationHeader(services, token); } dispatch(authActions.CONFIG({ config })); + dispatch(authActions.SET_HOME_CLUSTER(homeCluster || config.uuidPrefix)); if (token && user) { dispatch(authActions.INIT({ user, token })); dispatch(initSessions(services.authService, config, user));