Skip to content

Instantly share code, notes, and snippets.

@kocisov
Created April 30, 2017 19:17
Show Gist options
  • Save kocisov/2b3b152a681f3006911f8b95286c08e6 to your computer and use it in GitHub Desktop.
Save kocisov/2b3b152a681f3006911f8b95286c08e6 to your computer and use it in GitHub Desktop.
login
const USER_LOGGED_IN = '*/user/USER_LOGGED_IN'
const apiUrl = 'http://localhost:3000/api/login'
// If you haven't already installed redux-thunk middleware
// just do it LOL: https://github.com/gaearon/redux-thunk
// then doDis
function login ({ username, password }) {
return dispatch => {
fetch(`${apiUrl}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name,
password
})
})
.then(data => data.json())
.then(json => {
dispatch(USER_LOGGED_IN, json)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment