import { put, call } from "redux-saga/effects"; import * as actions from './../../../actions/auth/signIn' import axios from 'axios'; import { SIGN_IN_URL } from '../../../constants/index' import token from '../../../utils/token' // worker-saga for signing in export default function* ({ payload: { login, password } }) { try { const payload = yield call(() => axios.get(`${SIGN_IN_URL}login=${login}&password=${password}`) .then(({ data: [payload] }) => payload) ); yield call(() => { if (!payload) throw (new Error("No such email or password")) }); yield put(actions.signInRequestSucces(payload)); yield call(() => localStorage.setItem(token, JSON.stringify(payload))); } catch ({ message }) { yield put(actions.signInRequestFailure(message)); yield call(() => localStorage.removeItem(token)); } }