Front: gestion de la déconnexion
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { call, put } from 'redux-saga/effects';
|
||||
import { loginFailure, loginSuccess } from '../actions/auth.actions';
|
||||
import { loginFailure, loginSuccess, logoutFailure, logoutSuccess } from '../actions/auth.actions';
|
||||
import { addMessage } from '../actions/message.actions';
|
||||
|
||||
export function* loginSaga(action) {
|
||||
@ -34,4 +34,34 @@ function doLogin(username, password) {
|
||||
mode: 'cors',
|
||||
credentials: 'include'
|
||||
}).then(res => res.json())
|
||||
}
|
||||
|
||||
export function* logoutSaga(action) {
|
||||
let result;
|
||||
try {
|
||||
result = yield call(doLogout);
|
||||
} catch(err) {
|
||||
yield put(logoutFailure(err));
|
||||
yield put(addMessage('danger', "Une erreur inconnue bloque le fonctionnement normal de l'application. Veuillez réessayer plus tard."));
|
||||
}
|
||||
|
||||
if ('error' in result) {
|
||||
yield put(logoutFailure(action.username, result.error));
|
||||
const message = result.error.message ? result.error.message : result.error.toString();
|
||||
yield put(addMessage('danger', message));
|
||||
return
|
||||
}
|
||||
|
||||
yield put(logoutSuccess(action.username));
|
||||
}
|
||||
|
||||
function doLogout() {
|
||||
return fetch('http://localhost:8001/api/v1/logout', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
mode: 'cors',
|
||||
credentials: 'include'
|
||||
}).then(res => res.json())
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
import { all, takeLatest } from 'redux-saga/effects';
|
||||
import { LOGIN_REQUEST } from '../actions/auth.actions';
|
||||
import { loginSaga} from './auth.sagas';
|
||||
import { LOGIN_REQUEST, LOGOUT_REQUEST } from '../actions/auth.actions';
|
||||
import { loginSaga, logoutSaga } from './auth.sagas';
|
||||
import { PROJECT_USER_LIST, PROJECT_LIST } from '../actions/project';
|
||||
import { projectUserListSaga, projectListSaga } from './project';
|
||||
|
||||
export default function* rootSaga() {
|
||||
yield all([
|
||||
takeLatest(LOGIN_REQUEST, loginSaga),
|
||||
takeLatest(LOGOUT_REQUEST, logoutSaga),
|
||||
takeLatest(PROJECT_USER_LIST, projectUserListSaga),
|
||||
takeLatest(PROJECT_LIST, projectListSaga),
|
||||
]);
|
||||
|
Reference in New Issue
Block a user