Getting Auth and Subscription to work together

Hi, Thanks for detailed question!
Yes, adding auth over WebSocketLink is different than HttpLink. You need to pass header in connectionParams as below:

const wsLink = new WebSocketLink({
  uri: `wss://${ENDPOINT}`,
  options: {
    reconnect: true,
    connectionParams: {  "X-Auth0-Token": result.access_token, },});

Please check apollo docs Subscriptions - Client (React) - Apollo GraphQL Docs
And also make sure either you are running master or in slash , because this feature is not released yet.
Let me know if you still get this or any other issue related to auth and subscriptions.

1 Like