Apollo-client: How to use credentials: 'include' option for apollo-link-ws?

Created on 6 Sep 2019  路  2Comments  路  Source: apollographql/apollo-client

I am trying to log users in with sessions and cookies. I am in a different origin status with a development mode. I made CORS available on my Django server side.

I first attempt to log in by using axios and it works well. In the response header, it contains,

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: 192.168.0.6:19006
Set-Cookie:...

So login was successful and cookie was sent. But when I open a websocket connection after the intial login request, it does not work with Apollo Websocket. It fails to stay logged in and does not use the cookie assigned from the server. I am suspecting that it may be an issue with Apollo websocket and I found that I could have set a credential option for a normal HTTP request like this:

const link = createHttpLink({
  uri: '/graphql',
  credentials: 'same-origin'
});

https://www.apollographql.com/docs/react/recipes/authentication/

But I cannot find that option for apollo-link-ws nor subscriptions-transport-ws.

How can I set credentials: 'include' for apollo-link-ws?

Most helpful comment

Did you ever figure this out? Running in to the same thing

All 2 comments

Did you ever figure this out? Running in to the same thing

I am trying to log users in with sessions and cookies. I am in a different origin status with a development mode. I made CORS available on my Django server side.

I first attempt to log in by using axios and it works well. In the response header, it contains,

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: 192.168.0.6:19006
Set-Cookie:...

So login was successful and cookie was sent. But when I open a websocket connection after the intial login request, it does not work with Apollo Websocket. It fails to stay logged in and does not use the cookie assigned from the server. I am suspecting that it may be an issue with Apollo websocket and I found that I could have set a credential option for a normal HTTP request like this:

const link = createHttpLink({
  uri: '/graphql',
  credentials: 'same-origin'
});

https://www.apollographql.com/docs/react/recipes/authentication/

But I cannot find that option for apollo-link-ws nor subscriptions-transport-ws.

How can I set credentials: 'include' for apollo-link-ws?

Is this what you wanted?

https://www.apollographql.com/docs/react/networking/basic-http-networking/#including-credentials-in-requests

Was this page helpful?
0 / 5 - 0 ratings