Last active
August 3, 2020 19:27
-
-
Save YKalashnikov/5508fdd3e9714bac2f9cd9dec05fb823 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const userPostFetch = user => { | |
return dispatch => { | |
return fetch("http://localhost:3000/api/v1/users", { | |
method: "POST", | |
headers: { | |
'Content-Type': 'application/json', | |
Accept: 'application/json', | |
}, | |
body: JSON.stringify({user}) | |
}) | |
.then(resp => resp.json()) | |
.then(data => { | |
if (data.message) { | |
//Тут прописываем логику | |
} else { | |
localStorage.setItem("token", data.jwt) | |
dispatch(loginUser(data.user)) | |
} | |
}) | |
} | |
} | |
const loginUser = userObj => ({ | |
type: 'LOGIN_USER', | |
payload: userObj | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment