Set the token of the user synchronously if possible

This commit is contained in:
Grégoire Delattre 2019-05-19 17:59:23 +02:00
parent 8fc952b33c
commit 5b9e9b15d2

View File

@ -18,6 +18,12 @@ const defaultState = Map({
modulesLoading: false, modulesLoading: false,
}); });
let initialState = defaultState
const token = localStorage.getItem("token");
if (token && token !== "") {
initialState = updateFromToken(initialState, token)
}
const handlers = { const handlers = {
"USER_LOGIN_PENDING": state => state.set("loading", true), "USER_LOGIN_PENDING": state => state.set("loading", true),
"USER_LOGIN_ERROR": (state, action) => { "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; handlers[action.type] ? handlers[action.type](state, action) : state;