From 5b9e9b15d22fdf2dc8d0265e112e8b42f6fcfcb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Delattre?= Date: Sun, 19 May 2019 17:59:23 +0200 Subject: [PATCH] Set the token of the user synchronously if possible --- frontend/js/reducers/users.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/js/reducers/users.js b/frontend/js/reducers/users.js index db02c5d..0b7cad6 100644 --- a/frontend/js/reducers/users.js +++ b/frontend/js/reducers/users.js @@ -18,6 +18,12 @@ const defaultState = Map({ modulesLoading: false, }); +let initialState = defaultState +const token = localStorage.getItem("token"); +if (token && token !== "") { + initialState = updateFromToken(initialState, token) +} + const handlers = { "USER_LOGIN_PENDING": state => state.set("loading", true), "USER_LOGIN_ERROR": (state, action) => { @@ -81,5 +87,5 @@ function updateFromToken(state, token) { })) } -export default (state = defaultState, action) => +export default (state = initialState, action) => handlers[action.type] ? handlers[action.type](state, action) : state;