src/actions/index.js
// If so, load the user data
If so, load the user data
If so load the user data
function checkAuth() {
	return function(dispatch) {
		if(localStorage.getItem('token')) {
			axios.get(`${ROOT_URL}/users/current?token=${localStorage.getItem('token')}`)
				.then(({data}) => {
					dispatch({ type: AUTH_USER, user: data.user});
					browserHistory.push(`/${data.user.role}s/${data.user._id}`);
				})
				.catch(() => dispatch(authError('Something went wrong')));
		} else {
			dispatch(authError('Not logged in'));
		}
	}
}
function checkAuth ( ) { return function ( dispatch ) { if ( localStorage . getItem ( 'token' ) ) { axios . get ( ` ${ ROOT_URL } ${ localStorage . getItem ( 'token' ) } ` ) . then ( ( { data } ) => { dispatch ( { type : AUTH_USER , user : data . user } ) ; browserHistory . push ( ` ${ data . user . role } ${ data . user . _id } ` ) ; } ) . catch ( ( ) => dispatch ( authError ( 'Something went wrong' ) ) ) ; } else { dispatch ( authError ( 'Not logged in' ) ) ; } } }
If so, load the user data
If so load the user data