'Can't pass asynchronous headers for socket connection in React Native GraphQl(Apollo)
I'm trying to get and add my authorization token from the storage (AsyncStorage / EcnryptedStorage).Getting the token is asynchronous when announced I can not pass it to the headers. I guess it happens because. connectionParams section is designed for non-asynchronous LocalStorage, but in React Native all the manupulations with data from the storage are asynchronous
Code:
const wsLink = new WebSocketLink({
uri: `wss://myLinkWebsocket`,
options: {
lazy: true,
reconnect: true,
connectionParams: async () => {
const token = await EncryptedStorage.getItem('@access-token');
return {
headers: {
authorization: token ? `Bearer ${token}` : '',
},
};
},
},
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
