diff -r 7586b4a11c32 -r b2514a9bcd49 client/src/reducers/authReducer.js --- a/client/src/reducers/authReducer.js Tue Jun 20 12:11:57 2017 +0200 +++ b/client/src/reducers/authReducer.js Tue Jun 20 14:13:15 2017 +0200 @@ -1,7 +1,12 @@ +import Immutable from 'immutable'; import * as types from '../constants/actionTypes'; export const isAuthenticated = (state = false, action) => { switch (action.type) { + case types.AUTH_LOGOUT: + return false; + case types.AUTH_LOGIN_SUCCESS: + return true; default: return state; } @@ -10,15 +15,14 @@ export const currentUser = (state = null, action) => { switch (action.type) { case types.AUTH_LOGOUT: - localStorage.removeItem('currentUser'); return null; case types.AUTH_LOGIN_SUCCESS: - return action.user; + return Immutable.Map(action.user); case types.USER_UPDATE_SETTINGS: - state.first_name = action.firstname; - state.last_name = action.lastname; - localStorage.setItem('currentUser', JSON.stringify(state)); - return state; + return state.merge({ + first_name: action.firstname, + last_name: action.lastname + }); default: return state; } @@ -27,7 +31,6 @@ export const token = (state = null, action) => { switch (action.type) { case types.AUTH_LOGOUT: - localStorage.removeItem('token'); return null; case types.AUTH_STORE_TOKEN: return action.token; @@ -36,28 +39,27 @@ } } -// TODO Use Immutable.Map -const loginState = { +const loginState = Immutable.Map({ loading: false, success: false, error: false, -} +}); export const login = (state = loginState, action) => { switch (action.type) { case types.AUTH_LOGIN_REQUEST: - return { + return Immutable.Map({ loading: true, success: false, error: false, - } + }) case types.AUTH_LOGIN_SUCCESS: case types.AUTH_LOGIN_ERROR: - return { + return Immutable.Map({ loading: false, success: action.type === types.AUTH_LOGIN_SUCCESS, error: action.type === types.AUTH_LOGIN_ERROR, - } + }) default: return state }