Files
planka-zh/client/src/sagas/login/requests/login.js
Maksim Eltyshev 5ffef61fe7 Initial commit
2019-08-31 04:07:25 +05:00

30 lines
712 B
JavaScript
Executable File

import { call, put } from 'redux-saga/effects';
import { authenticateFailed, authenticateRequested, authenticateSucceeded } from '../../../actions';
import api from '../../../api';
// eslint-disable-next-line import/prefer-default-export
export function* authenticateRequest(data) {
yield put(authenticateRequested(data));
try {
const { item } = yield call(api.createAccessToken, data);
const action = authenticateSucceeded(item);
yield put(action);
return {
success: true,
payload: action.payload,
};
} catch (error) {
const action = authenticateFailed(error);
yield put(action);
return {
success: false,
payload: action.payload,
};
}
}