refs #14565-login
[arvados-workbench2.git] / src / store / users / users-actions.ts
index c1bad88b86928a77461df7b3435c7cc03c9c8131..eec1ebbdf292301bb3d8b35a9fbc5082eb10594f 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,10 +51,10 @@ 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 client = await services.apiClientAuthorizationService.create({ ownerUuid: uuid });
+        dispatch<any>(saveApiToken(`v2/${client.uuid}/${client.apiToken}`));
+        await location.reload();
         dispatch<any>(getUserDetails()).then(() => {
-            location.reload();
             dispatch<any>(navigateToRootProject);
         });
     };