user.js 734 Bytes
import axios from 'axios';

const REGISTER = 'user/REGISTER';
const LOGIN = 'user/LOGIN';

export function register(data) {
  const req = axios.post('http://localhost:4000/api/register', data)
    .then(res => res.data);

    return {
      type: REGISTER,
      payload: req,
    }
}

export function login(data) {
  const req = axios.post('http://localhost:4000/api/login', data)
    .then(res => res.date);

    return {
      type: LOGIN,
      payload: req,
    }
}

export default function (state = {}, action) {
  switch (action.type) {
    case REGISTER:
      return { ...state, registerSuccess: action.payload };
    case LOGIN:
      return { ...state, loginSuccess: action.payload };
    default:
      return state;
  }
}