【发布时间】:2019-08-12 17:57:12
【问题描述】:
我正在使用令牌通过 Apollo 客户端验证对我的服务器的请求,并复制了文档中提供的以下示例:
const httpLink = createHttpLink({ uri: 'http://0.0.0.0:3003' });
const authLink = setContext((_, { headers }) => {
// get the authentication token from local storage if it exists
const token = localStorage.getItem('token');
// return the headers to the context so httpLink can read them
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : '',
},
};
});
const apolloClient = new ApolloClient({
link: authLink.concat(httpLink),
});
这很好用,但最终令牌会过期,我需要更新 Apollo 客户端正在使用的令牌。
如果不实例化新的 Apollo 客户端,我该怎么做?
【问题讨论】: