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);