我正在尝试在客户端集成授权令牌。我在中间件中传递这个令牌。当用户注销时重置存储然后获取新令牌。现在,当我发送新请求时,它仍在发送旧令牌(缓存)
这是我的代码 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},`
});
}
当我注销时,我有这个代码
localStorage.removeItem(AUTH_TOKEN);
this._apollo.getClient().resetStore();
然后,当我发出另一个请求时,它仍在请求标头中使用旧令牌。
如何使用新令牌更新它?