Created
June 24, 2018 10:10
-
-
Save AndrejGajdos/dd3d83296cc87109b433b9a08b78d93c to your computer and use it in GitHub Desktop.
This file is part of project https://github.com/AndrejGajdos/auth-flow-spa-node-react
This file contains 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 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