Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
65 lines (51 loc) · 1.57 KB

File metadata and controls

65 lines (51 loc) · 1.57 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import axios from 'axios';
const serverUrl = 'https://build-and-go.herokuapp.com';
const LOGIN_USER = 'LOGIN_USER';
const SIGNUP_USER = 'SIGNUP_USER';
const REMOVE_USER = 'REMOVE_USER';
const EDIT_USER = 'EDIT_USER';
const loginUser = user => ({type: LOGIN_USER, user})
const signupUser = user => ({type: SIGNUP_USER, user})
const removeUser = () => ({type: REMOVE_USER})
const editUser = user => ({type: EDIT_USER, user})
export default function (user = {}, action) {
switch (action.type) {
case LOGIN_USER:
return action.user;
case SIGNUP_USER:
return action.user;
case REMOVE_USER:
return {};
case EDIT_USER:
return action.user;
default:
return user;
}
}
export const fetchUser = (user) => dispatch => {
return axios.post(`${serverUrl}/auth/login`, user)
.then(res => res.data)
.then(userData => {
dispatch(loginUser(userData))
return userData
})
.catch(err => console.warn(`error fetching user: ${user.email}`, err))
};
export const createUser = user => dispatch => {
axios.post(`${serverUrl}/auth/signup`, user)
.then(res => res.data)
.then(userData => {
dispatch(signupUser(userData))
return userData
})
.catch(err => console.warn('error creating user', err))
}
export const updateUser = (userId, edits) => dispatch => {
axios.put(`${serverUrl}/api/users/userId`, edits)
.then(res => res.data)
.then(userData => dispatch(editUser(userData)))
.catch(err => console.error(`error updating user: ${userId}`, err))
}
export const logout = () => dispatch => {
return dispatch(removeUser())
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.