Created
April 19, 2018 10:43
-
-
Save Tinusw/001dc8314f4cd67646ef5631e44c874f to your computer and use it in GitHub Desktop.
actions/index.js
This file contains hidden or 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, AUTH_ERROR } from "./types"; | |
const ROOT_URL = "http://localhost:"; | |
const PORT = "3030"; | |
export function signinUser({ email, password }) { | |
return ((dispatch) => { | |
return axios.post(`${ROOT_URL}${PORT}/signin`, { email, password }) | |
.then(response => { | |
// update state to be auth'd | |
dispatch({ type: AUTH_USER }); | |
// Save token locally | |
localStorage.setItem('token', response.data.token) | |
}) | |
.catch(error => { | |
dispatch({ type: AUTH_ERROR, payload: error }); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment