From 60267305cbd27a1db30c2e142acac1fefa1f2a20 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 25 Feb 2020 14:35:47 +0100 Subject: [PATCH] Ajout domaine 'init' dans les sagas --- frontend/src/sagas/init/root.saga.js | 8 ++++++++ frontend/src/sagas/init/session.saga.js | 11 +++++++++++ frontend/src/sagas/root.js | 2 ++ frontend/src/services/api-client.service.js | 4 ++-- 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 frontend/src/sagas/init/root.saga.js create mode 100644 frontend/src/sagas/init/session.saga.js diff --git a/frontend/src/sagas/init/root.saga.js b/frontend/src/sagas/init/root.saga.js new file mode 100644 index 0000000..324486f --- /dev/null +++ b/frontend/src/sagas/init/root.saga.js @@ -0,0 +1,8 @@ +import { all } from 'redux-saga/effects'; +import { checkSessionSaga } from './session.saga'; + +export function* rootSaga() { + yield all([ + checkSessionSaga(), + ]); +} diff --git a/frontend/src/sagas/init/session.saga.js b/frontend/src/sagas/init/session.saga.js new file mode 100644 index 0000000..65c37a1 --- /dev/null +++ b/frontend/src/sagas/init/session.saga.js @@ -0,0 +1,11 @@ +import { APIClient } from '../../services/api-client.service'; +import { call } from 'redux-saga/effects'; + +export function* checkSessionSaga() { + const client = new APIClient(); + try { + yield call(client.retrieveSessionUser); + } catch(err) { + console.error(err); + } +} diff --git a/frontend/src/sagas/root.js b/frontend/src/sagas/root.js index db8f90a..f2216bd 100644 --- a/frontend/src/sagas/root.js +++ b/frontend/src/sagas/root.js @@ -1,9 +1,11 @@ import { all } from 'redux-saga/effects'; import { rootSaga as authRootSaga } from './auth/root.saga'; import { rootSaga as failureRootSaga } from './failure/root.saga'; +import { rootSaga as initRootSaga } from './init/root.saga'; export default function* rootSaga() { yield all([ + initRootSaga(), authRootSaga(), failureRootSaga(), ]); diff --git a/frontend/src/services/api-client.service.js b/frontend/src/services/api-client.service.js index 058bc70..58d2da8 100644 --- a/frontend/src/services/api-client.service.js +++ b/frontend/src/services/api-client.service.js @@ -7,7 +7,7 @@ export class APIClient { this.baseURL = baseURL; this.login = this.login.bind(this); this.logout = this.logout.bind(this); - this.me = this.me.bind(this); + this.retrieveSessionUser = this.retrieveSessionUser.bind(this); this.listUsers = this.listUsers.bind(this); this.listRequests = this.listRequests.bind(this); } @@ -20,7 +20,7 @@ export class APIClient { return this._callAPI('/logout') } - me() { + retrieveSessionUser() { return this._callAPI('/me') }