user.js
859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}
};