Skip to content

Instantly share code, notes, and snippets.

@MeetMartin
Last active October 29, 2018 22:19
Show Gist options
  • Save MeetMartin/d3afc471595c9c62d2ac0d2795213a2f to your computer and use it in GitHub Desktop.
Save MeetMartin/d3afc471595c9c62d2ac0d2795213a2f to your computer and use it in GitHub Desktop.
imperative authReducer
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