I'm creating a login epic and dispatching multiple actions, the multiple actions are dispatched fine within 'CatchError' but produces an error "Actions must be plain objects. Use custom middleware for async actions." when dispatching the actions within the observable in the 'else' block.
export const loginUserEpic = action$ =>
action$.pipe(
ofType(LOGIN_USER),
switchMap(({ payload: { email, password } }) => {
const body = {
email: email,
password: password
};
return from(axios.post(`${process.env.REACT_APP_BACKEND}/api/auth/login`, body, config)).pipe(
map(response => {
if (response.data.user.is_active) {
return { type: "LOGIN_SUCCESS", payload: response.data };
} else {
return of(
{ type: "USER_LOADING" },
{ type: "TOGGLE_MODAL" },
updateModalData(modalTypes.EMAIL_SENT, "")
);
}
}),
catchError(err =>
of({ type: "LOGIN_FAIL" }, createAlert(alertTypes.RED_ALERT, err.data, err.status))
)
);
}));
react-reduxbut have you tried returning an array of actions, perhaps likefrom([action1, action2])? - Daniel BcreateAlertmight be creating a non-serializable action? Possiblyerr.datais non-serializable? But I'm not familiar with observables so I could be totally wrong. - Linda Paiste