Hi, currently I’m using ApolloLink from apollo client to set a Bearer token in the header of the request, the issue is when I want to refresh that access token and update my localStorage the token is still the same. I believe this happens because the instance of the client is still the same but I had not found a way to get what I want, please help?
Here is how I’m setting the client.
const authLink = new ApolloLink((operation, forward) => {
const accessToken = JSON.parse(localStorage.getItem('accessToken') || '');
operation.setContext(({ headers }: { headers: Headers }) => ({
headers: {
...headers,
authorization: `Bearer ${accessToken}`,
},
}))
return forward(operation)
})
const httpLink = new HttpLink({
uri: prodURI,
});
const apiClient = new ApolloClient({
link: from([errorLink, authLink, httpLink]),
cache: new InMemoryCache(),
});
export default apiClient;