我正在尝试在客户端集成授权令牌。我将这个令牌传递给中间件。当用户注销重置商店,然后得到一个新的令牌。现在,当我发出新的请求,它仍然是发送旧令牌(缓存)Apollo resetStore在Angular客户端中不工作
这里是我的代码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();
然后当我发出另一个请求时,它仍然在请求头中使用旧的令牌。
如何使用新令牌进行更新?