Created
April 30, 2017 19:17
-
-
Save kocisov/2b3b152a681f3006911f8b95286c08e6 to your computer and use it in GitHub Desktop.
login
This file contains hidden or 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
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