Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Enable credentials: 'same-origin' by default (or allow an option to enable it easily) #83

Closed
maktouch opened this issue Sep 22, 2017 · 5 comments

Comments

@maktouch
Copy link

The old ApolloClient automatically passed cookies.
HttpLink, BatchHttpLink uses apollo-fetch, which uses isomorphic-fetch. By default, isomorphic-fetch doesn't send cookies.

The current workaround is pretty complicated:

    const uri = '/api/graphql';

    // by default, apollo-link-http doesn't send cookies
    const customFetch = (uri, options) =>
        fetch(uri, {
            ...options,
            credentials: 'same-origin',
        });

    // create an apollo fetch instance with our hacked fetch instance
    const apolloFetch = createApolloFetch({
        uri,
        customFetch,
    });

    const link = new BatchHttpLink({ uri, fetch: apolloFetch })

This problem can be solved in multiple ways:

  1. we could enable it by default to mimic the old version
  2. we could add another option to apollo-link-http and apollo-link-batch-http, called fetchOption, so we could just do something like
const fetchOptions = {
    credentials: 'same-origin',
};

const link = new BatchHttpLink({ uri, fetchOptions });

I'm willing to do the fix + the tests, just need help on figuring which way we want to go :-)

Intended outcome:
Cookies should be sent when doing a request

Actual outcome:
No cookies are being sent

@maktouch
Copy link
Author

Bleh, duplicate of #44

Sorry!

@mjfaga
Copy link

mjfaga commented Nov 29, 2017

I'm not sure this is truly a full duplicate of #44. That issue only addressed HttpLink, not BatchHttpLink. We still need to use that same workaround until BatchHttpLink is updated to also support credentials.

Can we re-open this issue until BatchHttpLink is also addressed?

@kimberlysuazo
Copy link

+1 to @mjfaga, I'm having this same issue with BatchHttpLink

@kamranayub
Copy link

Agreed, this is still an open issue for batch 👍

@maktouch maktouch reopened this Jan 9, 2018
@maktouch
Copy link
Author

maktouch commented Jan 9, 2018

Seems like another issue was open for this #343, I'll reclose this.

@maktouch maktouch closed this as completed Jan 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants