Skip to content

Instantly share code, notes, and snippets.

@AndrejGajdos
Created June 24, 2018 10:10
Show Gist options
  • Save AndrejGajdos/dd3d83296cc87109b433b9a08b78d93c to your computer and use it in GitHub Desktop.
Save AndrejGajdos/dd3d83296cc87109b433b9a08b78d93c to your computer and use it in GitHub Desktop.
import Cookies from 'js-cookie';
import * as ActionTypes from '../constants/actionTypes';
const initialState = {
user: {
isAuthenticated: typeof Cookies.get('auth__flow__spa__loggedUserObj') !== 'undefined',
loggedUserObj: Cookies.getJSON('auth__flow__spa__loggedUserObj'),
},
error: null,
};
export default function access(state = initialState, action) {
switch (action.type) {
case ActionTypes.LOGIN_SUCCEEDED:
case ActionTypes.PROFILE_SUCCEEDED: {
return {
...state,
user: {
...state.user,
isAuthenticated: true,
loggedUserObj: action.user,
},
error: null,
};
}
case ActionTypes.LOGIN_FAILED: {
return {
...state,
error: action.error,
};
}
case ActionTypes.PROFILE_FAILED:
case ActionTypes.LOGOUT_SUCCEEDED: {
return {
...state,
user: {
isAuthenticated: false,
},
error: null,
};
}
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment