svelte-apollo
svelte-apollo copied to clipboard
How to add wsLink with headers (auth:token) into the client?
trafficstars
In this link I've read how to set up httpLink with headers: {authorization: Bearer "+ getToken() } https://github.com/timhall/svelte-apollo/issues/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
@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}` : '',
},
};
},
},
});