15088: Fixes page refresh on link accounts page
[arvados.git] / src / store / users / users-actions.ts
index 4780aa728362aa7fdf0d536ed583827e8a007321..caf466f7ed89bb3937bae4e6a5882e77fd0aa592 100644 (file)
@@ -34,7 +34,7 @@ export const openUserAttributes = (uuid: string) =>
     };
 
 export const openUserManagement = (uuid: string) =>
-    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const { resources } = getState();
         const data = getResource<UserResource>(uuid)(resources);
         dispatch(dialogActions.OPEN_DIALOG({ id: USER_MANAGEMENT_DIALOG, data }));
@@ -51,8 +51,13 @@ export const openSetupShellAccount = (uuid: string) =>
 
 export const loginAs = (uuid: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
-        const client = await services.apiClientAuthorizationService.get(uuid);
-        dispatch<any>(saveApiToken(client.apiToken));
+        const { resources } = getState();
+        const data = getResource<UserResource>(uuid)(resources);
+        if (data) {
+            services.authService.saveUser(data);
+        }
+        const client = await services.apiClientAuthorizationService.create({ ownerUuid: uuid });
+        dispatch<any>(saveApiToken(`v2/${client.uuid}/${client.apiToken}`));
         location.reload();
         dispatch<any>(navigateToRootProject);
     };