1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 15:49:46 +02:00
planka/client/src/sagas/login/services/login.js

34 lines
861 B
JavaScript
Raw Normal View History

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';
import api from '../../../api';
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));
2023-09-04 10:06:59 -05:00
let accessToken = data.access_token;
try {
2023-09-04 10:06:59 -05:00
if (accessToken) {
({ item: accessToken } = yield call(api.exchangeOidcToken, accessToken));
} else {
({ item: accessToken } = yield call(api.createAccessToken, data));
}
} catch (error) {
2022-08-04 13:31:14 +02:00
yield put(actions.authenticate.failure(error));
return;
}
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,
};