Skip to content

Instantly share code, notes, and snippets.

@Tinusw
Created April 19, 2018 10:43
Show Gist options
  • Save Tinusw/001dc8314f4cd67646ef5631e44c874f to your computer and use it in GitHub Desktop.
Save Tinusw/001dc8314f4cd67646ef5631e44c874f to your computer and use it in GitHub Desktop.
actions/index.js
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