import { call, put } from 'redux-saga/effects'; import { LOGIN_FAILURE, LOGIN_SUCCESS } from '../actions/login'; export default function* loginSaga(action) { let result; try { result = yield call(doLogin, action.username, action.password); } catch(err) { yield put({ type: LOGIN_FAILURE, err }); } if ('Error' in result) { yield put({type: LOGIN_FAILURE, err: result.Error}); return } yield put({type: LOGIN_SUCCESS, data: result.Data }); } function doLogin(username, password) { return fetch('http://192.168.0.126:3000/login', { method: 'POST', body: JSON.stringify({ Username: username, Password: password }), mode: 'cors', credentials: 'include' }) .then(res => res.json()) }