Skip to content

Instantly share code, notes, and snippets.

@YKalashnikov
Last active August 3, 2020 19:27
Show Gist options
  • Save YKalashnikov/5508fdd3e9714bac2f9cd9dec05fb823 to your computer and use it in GitHub Desktop.
Save YKalashnikov/5508fdd3e9714bac2f9cd9dec05fb823 to your computer and use it in GitHub Desktop.
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