Guest User

Untitled

a guest
Jun 25th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import Cookies from 'js-cookie';
  2. import * as ActionTypes from '../constants/actionTypes';
  3.  
  4. const initialState = {
  5. user: {
  6. isAuthenticated: typeof Cookies.get('auth__flow__spa__loggedUserObj') !== 'undefined',
  7. loggedUserObj: Cookies.getJSON('auth__flow__spa__loggedUserObj'),
  8. },
  9. error: null,
  10. };
  11.  
  12. export default function access(state = initialState, action) {
  13. switch (action.type) {
  14. case ActionTypes.LOGIN_SUCCEEDED:
  15. case ActionTypes.PROFILE_SUCCEEDED: {
  16. return {
  17. ...state,
  18. user: {
  19. ...state.user,
  20. isAuthenticated: true,
  21. loggedUserObj: action.user,
  22. },
  23. error: null,
  24. };
  25. }
  26. case ActionTypes.LOGIN_FAILED: {
  27. return {
  28. ...state,
  29. error: action.error,
  30. };
  31. }
  32. case ActionTypes.PROFILE_FAILED:
  33. case ActionTypes.LOGOUT_SUCCEEDED: {
  34. return {
  35. ...state,
  36. user: {
  37. isAuthenticated: false,
  38. },
  39. error: null,
  40. };
  41. }
  42. default:
  43. return state;
  44. }
  45. }
Add Comment
Please, Sign In to add comment