Skip to content

Instantly share code, notes, and snippets.

@gugat
Created April 10, 2019 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugat/2adf5f574a04c6c40000d5042b1231c4 to your computer and use it in GitHub Desktop.
Save gugat/2adf5f574a04c6c40000d5042b1231c4 to your computer and use it in GitHub Desktop.
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