Skip to content

Instantly share code, notes, and snippets.

@gugat
Created April 10, 2019 01:16
Show Gist options
  • Select an option

  • Save gugat/2adf5f574a04c6c40000d5042b1231c4 to your computer and use it in GitHub Desktop.

Select an option

Save gugat/2adf5f574a04c6c40000d5042b1231c4 to your computer and use it in GitHub Desktop.

Revisions

  1. gugat created this gist Apr 10, 2019.
    33 changes: 33 additions & 0 deletions login_react_native.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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))
    })
    })
    }
    }