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

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

const InitialState = {
  logged: false,
  name: 'test',
  id: 'test123',
  password: 'test1111~',
  gender: '1',
};

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

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

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

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

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