I am trying to integrate authorization token at the client side. I am passing this token in middleware. When user logout reset the store and then get a new token. Now when I send new request it is still sending the old token(cached)
Here is my code app.module.ts
const networkInterface = createNetworkInterface({
uri: "http://localhost:3000/graphql"
});
networkInterface.use([
{
applyMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {}; // Create the header object if needed.
}
req.options.headers.authorization = localStorage.getItem(AUTH_TOKEN);
next();
}
}
]);
export function provideClient(): ApolloClient {
return new ApolloClient({
networkInterface,
dataIdFromObject: (o: any) => `${o.__typename}-${o.id},`
});
}
When I do logout I have this code
localStorage.removeItem(AUTH_TOKEN);
this._apollo.getClient().resetStore();
Then When I make another request it is still taking old token in request headers.
How can I update this with the new token?