Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add wsLink with headers (auth:token) into the client? #79

Open
beebase opened this issue Jan 19, 2021 · 1 comment
Open

How to add wsLink with headers (auth:token) into the client? #79

beebase opened this issue Jan 19, 2021 · 1 comment

Comments

@beebase
Copy link

beebase commented Jan 19, 2021

In this link I've read how to set up httpLink with headers: {authorization: Bearer "+ getToken() }
#30

I would also like to add a wsLink with:
connectionParams: {headers: {authorisation: Bearer + getToken() }
but I can't find any example on the internet

@chbert
Copy link
Contributor

chbert commented Mar 2, 2021

@beebase That's how I implemented (not sure if this is the best approach, though):

const wsLink = new WebSocketLink({
  uri: WS_GRAPHQL_ENDPOINT,
  options: {
    lazy: true,
    reconnect: true,
    connectionParams: async () => {
      const token = await getToken();

      return {
        headers: {
          authorization: token ? `Bearer ${token}` : '',
        },
      };
    },
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants