Created
April 10, 2019 01:16
-
-
Save gugat/2adf5f574a04c6c40000d5042b1231c4 to your computer and use it in GitHub Desktop.
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
export const signIn = (email, password) => { | |
return (dispatch, getState) => { | |
return new Promise((resolve, reject) => { | |
return fetch(`${BASE_URL}/auth/sign_in`, { | |
method: 'POST', | |
timeout: REQUEST_TIMEOUT, | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify({ | |
email, | |
password | |
}), | |
}) | |
.then(handleFetchErrors) | |
.then(res => res.json().then(json => ({ | |
headers: res.headers, | |
status: res.status, | |
json | |
}))) | |
.then(({ headers, status, json }) => { | |
const promises = getAvailableHeaders(headers) | |
Promise.all(promises).then(credentials => { | |
return resolve(true); | |
}) | |
}) | |
.catch(error => { | |
parseFetchError(error) | |
.then(errorObject => reject(errorObject)) | |
}) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment