Last active
October 29, 2018 22:19
-
-
Save MeetMartin/d3afc471595c9c62d2ac0d2795213a2f to your computer and use it in GitHub Desktop.
imperative authReducer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SET_CURRENT_USER } from '../actions/types'; | |
import { isEmpty } from '../../utilities/validations'; | |
const initialState = { | |
isAuthenticated: false, | |
user: {} | |
}; | |
/** | |
* Authentication reducer | |
* @param {object} state reducer state | |
* @param {object} action reducer action | |
* @returns {object} authReducer :: (object, object) -> object | |
*/ | |
export default function (state = initialState, action = null) { | |
switch (action.type) { | |
case SET_CURRENT_USER: | |
return ({ | |
...state, | |
isAuthenticated: !isEmpty(action.payload), | |
user: action.payload | |
}); | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment