Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails、GraphQL和React路由器:InvalidAuthenticationToken_Ruby On Rails_Reactjs_Graphql_React Apollo - Fatal编程技术网

Ruby on rails Rails、GraphQL和React路由器:InvalidAuthenticationToken

Ruby on rails Rails、GraphQL和React路由器:InvalidAuthenticationToken,ruby-on-rails,reactjs,graphql,react-apollo,Ruby On Rails,Reactjs,Graphql,React Apollo,我正在尝试使用React和React路由器dom设置GraphQL。我正在运行来自不同视图的查询。我已经在Apollo上设置了csrf令牌,第一个查询运行得很好,但是如果我转到另一个执行查询的路由,我会得到:InvalidAuthenticityToken。是否每次执行都要刷新令牌 这是我的客户设置 var-csrfToken:any=document.querySelector('meta[name=csrf-token')!。getAttribute('content'); const ht

我正在尝试使用React和React路由器dom设置GraphQL。我正在运行来自不同视图的查询。我已经在Apollo上设置了csrf令牌,第一个查询运行得很好,但是如果我转到另一个执行查询的路由,我会得到:InvalidAuthenticityToken。是否每次执行都要刷新令牌

这是我的客户设置

var-csrfToken:any=document.querySelector('meta[name=csrf-token')!。getAttribute('content');
const httpLink=新的httpLink({
凭据:“相同来源”,
标题:{
“X-CSRF-Token”:csrfToken
}
})
const authLink=setContext(({headers})=>{
//从本地存储中获取身份验证令牌(如果存在)
const token=Cookies.get('token');
//将标题返回到上下文,以便httpLink可以读取它们
返回{
标题:{
…标题,
授权:令牌?令牌:“”,
}
}
});
const客户端=新客户端({
链接:authLink.concat(httpLink),
缓存:新的InMemoryCache()
});
谢谢你的建议