2019-08-31 04:07:25 +05:00
|
|
|
import { call, put } from 'redux-saga/effects';
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
import actions from '../../../actions';
|
2021-06-24 01:05:22 +05:00
|
|
|
import api from '../../../api';
|
2022-09-07 18:39:33 +05:00
|
|
|
import { setAccessToken } from '../../../utils/access-token-storage';
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
export function* authenticate(data) {
|
|
|
|
yield put(actions.authenticate(data));
|
2021-06-24 01:05:22 +05:00
|
|
|
|
|
|
|
let accessToken;
|
|
|
|
try {
|
|
|
|
({ item: accessToken } = yield call(api.createAccessToken, data));
|
|
|
|
} catch (error) {
|
2022-08-04 13:31:14 +02:00
|
|
|
yield put(actions.authenticate.failure(error));
|
2021-06-24 01:05:22 +05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-07 18:39:33 +05:00
|
|
|
yield call(setAccessToken, accessToken);
|
2022-08-04 13:31:14 +02:00
|
|
|
yield put(actions.authenticate.success(accessToken));
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
export function* clearAuthenticateError() {
|
|
|
|
yield put(actions.clearAuthenticateError());
|
2019-08-31 04:07:25 +05:00
|
|
|
}
|
2022-08-04 13:31:14 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
authenticate,
|
|
|
|
clearAuthenticateError,
|
|
|
|
};
|