Last active
June 26, 2017 19:43
-
-
Save jwill9999/d1dae930fb637c15c5acf9c00958ba4a to your computer and use it in GitHub Desktop.
action.js
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 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