This repository has been archived on 2025-10-28. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
dashboard/src/services/auth/redux/reducers.ts
2022-02-10 13:34:44 +00:00

32 lines
867 B
TypeScript

import { createApiReducer, chainReducers, INITIAL_API_STATUS } from 'src/services/api';
import { AuthState } from './types';
import { AuthActionTypes } from './actions';
import { CurrentUser } from '../types';
const initialCurrentUserState: CurrentUser = {
email: null,
name: null,
preferredUsername: null,
id: null,
};
const initialState: AuthState = {
token: null,
userInfo: initialCurrentUserState,
_status: INITIAL_API_STATUS,
};
const auth = createApiReducer(
[AuthActionTypes.SIGN_IN_START, AuthActionTypes.SIGN_IN_SUCCESS, AuthActionTypes.SIGN_IN_FAILURE],
(data) => ({ token: data.accessToken, userInfo: data.userInfo }),
(data) => data.error.message,
);
const signOut = createApiReducer(
['', AuthActionTypes.SIGN_OUT, ''],
() => initialState,
() => initialState,
);
export default chainReducers(initialState, auth, signOut);