From 4b0674a49d4be6e82ad2d7904e4066d2512fbbc3 Mon Sep 17 00:00:00 2001 From: Kenneth Jiang Date: Wed, 10 Oct 2018 10:36:46 -0700 Subject: [PATCH 1/2] Load initial currentUser state from localstorage --- src/reducers/currentUser.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/reducers/currentUser.js b/src/reducers/currentUser.js index 9a38a1a..0771001 100644 --- a/src/reducers/currentUser.js +++ b/src/reducers/currentUser.js @@ -1,4 +1,5 @@ import jwtDecode from 'jwt-decode'; +import { hasAuthToken, getAuthToken } from '..//actions/authTokenStore'; const initialState = {}; @@ -17,6 +18,12 @@ const currentUser = (state = initialState, action) => { case 'LOGIN_FAILED': return initialState; default: + if (_.isEmpty(state) && hasAuthToken()) { + return { + isLoggedIn: true, + ...jwtDecode(getAuthToken()) + }; + } return state; } }; From 9099a061b41fbbac4c4674cd47051a8703d29fc8 Mon Sep 17 00:00:00 2001 From: Kenneth Jiang Date: Wed, 10 Oct 2018 10:42:32 -0700 Subject: [PATCH 2/2] Remove dependency. Some comments --- src/reducers/currentUser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reducers/currentUser.js b/src/reducers/currentUser.js index 0771001..76b81c3 100644 --- a/src/reducers/currentUser.js +++ b/src/reducers/currentUser.js @@ -1,5 +1,5 @@ import jwtDecode from 'jwt-decode'; -import { hasAuthToken, getAuthToken } from '..//actions/authTokenStore'; +import { hasAuthToken, getAuthToken } from '../actions/authTokenStore'; const initialState = {}; @@ -18,7 +18,7 @@ const currentUser = (state = initialState, action) => { case 'LOGIN_FAILED': return initialState; default: - if (_.isEmpty(state) && hasAuthToken()) { + if (Object.keys(state).length === 0 && hasAuthToken()) { // Try to establish init state when it is empty return { isLoggedIn: true, ...jwtDecode(getAuthToken())