X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/16b7bebe83b28b5622f23385df5cacbd66bc425b..f626dd268140b4ef406a2ec0c6568f6ca0298e1d:/src/store/auth/auth-action.ts diff --git a/src/store/auth/auth-action.ts b/src/store/auth/auth-action.ts index dbf9a0f4..e9930a02 100644 --- a/src/store/auth/auth-action.ts +++ b/src/store/auth/auth-action.ts @@ -2,41 +2,29 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { serverApi } from "../../common/server-api"; import { ofType, default as unionize, UnionOf } from "unionize"; import { Dispatch } from "redux"; +import { authService } from "../../services/services"; +import { User } from "../../models/user"; -export interface UserDetailsResponse { - email: string; - first_name: string; - last_name: string; - is_admin: boolean; -} - -const actions = unionize({ +export const authActions = unionize({ SAVE_API_TOKEN: ofType(), LOGIN: {}, LOGOUT: {}, INIT: {}, USER_DETAILS_REQUEST: {}, - USER_DETAILS_SUCCESS: ofType() + USER_DETAILS_SUCCESS: ofType() }, { tag: 'type', value: 'payload' }); -export type AuthAction = UnionOf; -export default actions; - -export const getUserDetails = () => (dispatch: Dispatch) => { - dispatch(actions.USER_DETAILS_REQUEST()); - serverApi - .get('/users/current') - .then(resp => { - dispatch(actions.USER_DETAILS_SUCCESS(resp.data)); - }) - // .catch(err => { - // }); +export const getUserDetails = () => (dispatch: Dispatch): Promise => { + dispatch(authActions.USER_DETAILS_REQUEST()); + return authService.getUserDetails().then(details => { + dispatch(authActions.USER_DETAILS_SUCCESS(details)); + return details; + }); }; - +export type AuthAction = UnionOf;