Created
February 11, 2017 01:39
-
-
Save tsongas/a5dd70e887a2eff2aabec44c821c813e to your computer and use it in GitHub Desktop.
axios example
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
export function loginUser(employeeId, password) { | |
return function(dispatch) { | |
axios.post(`${ROOT_URL}/authenticate`, { employeeId, password }) | |
.then(response => { | |
dispatch({ type: AUTH_USER }); | |
localStorage.setItem('id', response.data.id); | |
localStorage.setItem('token', response.data.token); | |
browserHistory.push('/home'); | |
}) | |
.catch(() => { | |
dispatch(authError('Invalid employee ID or password.')); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment