Skip to content

Instantly share code, notes, and snippets.

@tsongas
Created February 11, 2017 01:39
Show Gist options
  • Save tsongas/a5dd70e887a2eff2aabec44c821c813e to your computer and use it in GitHub Desktop.
Save tsongas/a5dd70e887a2eff2aabec44c821c813e to your computer and use it in GitHub Desktop.
axios example
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