Merge branch 'master'
[arvados.git] / src / store / auth / auth-action.ts
index dbf9a0f4190db63905525b41f3185787d25e86f8..a6e6f79794db27bc64178b6f53626c6e688c3865 100644 (file)
@@ -2,16 +2,10 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { serverApi } from "../../common/server-api";
 import { ofType, default as unionize, UnionOf } from "unionize";
 import { Dispatch } from "redux";
-
-export interface UserDetailsResponse {
-    email: string;
-    first_name: string;
-    last_name: string;
-    is_admin: boolean;
-}
+import { authService } from "../../services/services";
+import { User } from "../../models/user";
 
 const actions = unionize({
     SAVE_API_TOKEN: ofType<string>(),
@@ -19,24 +13,20 @@ const actions = unionize({
     LOGOUT: {},
     INIT: {},
     USER_DETAILS_REQUEST: {},
-    USER_DETAILS_SUCCESS: ofType<UserDetailsResponse>()
+    USER_DETAILS_SUCCESS: ofType<User>()
 }, {
     tag: 'type',
     value: 'payload'
 });
 
-export type AuthAction = UnionOf<typeof actions>;
-export default actions;
-
-export const getUserDetails = () => (dispatch: Dispatch) => {
+export const getUserDetails = () => (dispatch: Dispatch): Promise<User> => {
     dispatch(actions.USER_DETAILS_REQUEST());
-    serverApi
-        .get<UserDetailsResponse>('/users/current')
-        .then(resp => {
-            dispatch(actions.USER_DETAILS_SUCCESS(resp.data));
-        })
-        // .catch(err => {
-        // });
+    return authService.getUserDetails().then(details => {
+        dispatch(actions.USER_DETAILS_SUCCESS(details));
+        return details;
+    });
 };
 
 
+export type AuthAction = UnionOf<typeof actions>;
+export default actions;