Set the token of the user synchronously if possible
This commit is contained in:
parent
8fc952b33c
commit
5b9e9b15d2
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user