// SPDX-License-Identifier: AGPL-3.0
import { ofType, default as unionize, UnionOf } from "unionize";
-import { UserDetailsResponse } from "../../services/auth-service/auth-service";
+import { Dispatch } from "redux";
+import { User } from "../../models/user";
+import { RootState } from "../store";
+import { ServiceRepository } from "../../services/services";
-const actions = unionize({
+export const authActions = unionize({
SAVE_API_TOKEN: ofType<string>(),
LOGIN: {},
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, getState: () => RootState, services: ServiceRepository): Promise<User> => {
+ dispatch(authActions.USER_DETAILS_REQUEST());
+ return services.authService.getUserDetails().then(details => {
+ dispatch(authActions.USER_DETAILS_SUCCESS(details));
+ return details;
+ });
+};
+
+export type AuthAction = UnionOf<typeof authActions>;