Request cookies not being passed when `same-origin` is set.
See original GitHub issueIntended outcome:
Want request cookies to be sent with query when same-origin
is set.
Actual outcome: I followed the new docs for Authentication but the Request Cookies are not being passed.
This worked before upgrading and I haven’t changed any code besides what was in the migration guide.
Code from 1.0.1 (worked fine, Request cookie is passed and came back with data)
import { ApolloProvider } from 'react-apollo'
import ApolloClient, { createNetworkInterface } from 'apollo-client'
const networkInterface = createNetworkInterface({
uri: '/graphql',
opts: {
credentials: 'same-origin',
},
});
const client = new ApolloClient({
networkInterface,
});
const Root = () => {
return (
<ApolloProvider client={ client }>
<Header />
</ApolloProvider>
);
};
ReactDOM.render(<Root />, document.querySelector('#root'));
Network tab:
Updated code to reflect 2.0.1 API:
import ApolloClient from 'apollo-client'
import { ApolloProvider } from 'react-apollo'
import { createHttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
import Header from './components/Header'
const link = createHttpLink({
uri: '/graphql',
opts: {
credentials: 'same-origin',
},
});
const client = new ApolloClient({
cache: new InMemoryCache(),
link
});
const Root = () => {
return (
<ApolloProvider client={ client }>
<Header />
</ApolloProvider>
)
}
ReactDOM.render(<Root />, document.querySelector('#root'));
Network Tab:
How to reproduce the issue:
Upgrade and use createHttpLink
with opts: { credentials: ‘same-origion’ } and see no Request cookie passed. I’m using express-session
on the backend, and have tried using cors
as mentioned in the docs but to no avail.
I’m not sure how to better debug but would love to know how so I can help fix it (if it is a problem). I could be messing something up but only upgrade-to-2.0 code changed so it seems suspect.
Version
- apollo-client@2.0.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:31 (2 by maintainers)
Top GitHub Comments
I moved to credentials: ‘include’
same-origin will check scheme, hostname and port.
After switching to ‘include’ I also had to fix up my CORS.
In some docs. it says to use HttpLink :
import { HttpLink } from 'apollo-link-http'
; and in some other part of the docs (in migration) it says to use createHttpLink :import { createHttpLink } from 'apollo-link-http'
. I tried both but the request cookies are still not passing.Here is what I have.