merge-conflicts
[arvados-workbench2.git] / src / store / auth / auth-action.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { ofType, default as unionize, UnionOf } from "unionize";
6 import { Dispatch } from "redux";
7 import { authService } from "../../services/services";
8 import { User } from "../../models/user";
9
10 const actions = unionize({
11     SAVE_API_TOKEN: ofType<string>(),
12     LOGIN: {},
13     LOGOUT: {},
14     INIT: {},
15     USER_DETAILS_REQUEST: {},
16     USER_DETAILS_SUCCESS: ofType<User>()
17 }, {
18     tag: 'type',
19     value: 'payload'
20 });
21
22 export const getUserDetails = () => (dispatch: Dispatch): Promise<User> => {
23     dispatch(actions.USER_DETAILS_REQUEST());
24     return authService.getUserDetails().then(details => {
25         dispatch(actions.USER_DETAILS_SUCCESS(details));
26         return details;
27     });
28 };
29
30
31 export type AuthAction = UnionOf<typeof actions>;
32 export default actions;