Skip to content

Instantly share code, notes, and snippets.

@jwill9999
Last active June 26, 2017 19:43
Show Gist options
  • Save jwill9999/d1dae930fb637c15c5acf9c00958ba4a to your computer and use it in GitHub Desktop.
Save jwill9999/d1dae930fb637c15c5acf9c00958ba4a to your computer and use it in GitHub Desktop.
action.js
import axios from 'axios';
import {AUTH_USER, UNAUTH_USER, AUTH_ERROR} from './types';
import authError from './error';
const ROOT_URL = 'http://localhost:3000/'; // url to api
export default function signinUser(email,password) {
return function(dispatch) {
// Submit email/password to the server
axios.post(`${ROOT_URL}signin`, { email, password }) //make api call and returns a promise
.then((response) => {
//update state
dispatch({ // once returned dispatch to your reducers
type: AUTH_USER
});
})
.catch((err) => {
dispatch(authError('I can\'t find you ... Please try again')); // catch any errors
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment