You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
861 B
JavaScript
34 lines
861 B
JavaScript
import { call, put } from 'redux-saga/effects';
|
|
|
|
import actions from '../../../actions';
|
|
import api from '../../../api';
|
|
import { setAccessToken } from '../../../utils/access-token-storage';
|
|
|
|
export function* authenticate(data) {
|
|
yield put(actions.authenticate(data));
|
|
|
|
let accessToken = data.access_token;
|
|
try {
|
|
if (accessToken) {
|
|
({ item: accessToken } = yield call(api.exchangeOidcToken, accessToken));
|
|
} else {
|
|
({ item: accessToken } = yield call(api.createAccessToken, data));
|
|
}
|
|
} catch (error) {
|
|
yield put(actions.authenticate.failure(error));
|
|
return;
|
|
}
|
|
|
|
yield call(setAccessToken, accessToken);
|
|
yield put(actions.authenticate.success(accessToken));
|
|
}
|
|
|
|
export function* clearAuthenticateError() {
|
|
yield put(actions.clearAuthenticateError());
|
|
}
|
|
|
|
export default {
|
|
authenticate,
|
|
clearAuthenticateError,
|
|
};
|