From 8df09b8ee52974e5bcd5fea862c3639f54afb54b Mon Sep 17 00:00:00 2001 From: Pawel Kowalczyk Date: Thu, 3 Jan 2019 14:27:06 +0100 Subject: [PATCH] refs #14565-login-as-other-user Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- src/services/auth-service/auth-service.ts | 4 ++-- src/store/users/users-actions.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts index 8601e208..6fe27c8d 100644 --- a/src/services/auth-service/auth-service.ts +++ b/src/services/auth-service/auth-service.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { getUserFullname, User, UserPrefs } from "~/models/user"; +import { getUserFullname, User, UserPrefs, UserResource } from '~/models/user'; import { AxiosInstance } from "axios"; import { ApiActions } from "~/services/api/api-actions"; import * as uuid from "uuid/v4"; @@ -77,7 +77,7 @@ export class AuthService { : undefined; } - public saveUser(user: User) { + public saveUser(user: User | UserResource) { localStorage.setItem(USER_EMAIL_KEY, user.email); localStorage.setItem(USER_FIRST_NAME_KEY, user.firstName); localStorage.setItem(USER_LAST_NAME_KEY, user.lastName); diff --git a/src/store/users/users-actions.ts b/src/store/users/users-actions.ts index eec1ebbd..066aa80b 100644 --- a/src/store/users/users-actions.ts +++ b/src/store/users/users-actions.ts @@ -51,12 +51,15 @@ export const openSetupShellAccount = (uuid: string) => export const loginAs = (uuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const { resources } = getState(); + const data = getResource(uuid)(resources); + if (data) { + services.authService.saveUser(data); + } const client = await services.apiClientAuthorizationService.create({ ownerUuid: uuid }); dispatch(saveApiToken(`v2/${client.uuid}/${client.apiToken}`)); - await location.reload(); - dispatch(getUserDetails()).then(() => { - dispatch(navigateToRootProject); - }); + location.reload(); + dispatch(navigateToRootProject); }; export const openUserCreateDialog = () => -- 2.30.2