Cookie未通过RelayJS在graphql请求中的移动浏览器中传递 [英] Cookies not getting passed in mobile browser in graphql request through relayjs

查看:123
本文介绍了Cookie未通过RelayJS在graphql请求中的移动浏览器中传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码段从Graphql查询数据时,我可以在标头中发送cookie:

I am able to send cookies in header while querying data from Graphql using this code snippet :

Relay.injectNetworkLayer(
新的Relay.DefaultNetworkLayer(GQL_URL,{
凭证:'same-origin',
}));

这对于桌面浏览器非常有效,但不适用于移动设备。


但是,当我在移动设备中打开网站(或使用任何移动设备模型在chrome中模拟)时,没有通过。

This works well for Desktop browser but not from mobile.

But when i open my website in mobile (or simulate in chrome using any mobile model) cookies are not getting passed.

是否有针对Cookie设置的移动浏览器特定处理?

PS:这可能不相关,但在台式机上,cookies将存储在不同的域中名称(因为有多个域用于不同的请求):

P.S.: This might not be relevant but in case of desktop, cookies are getting stored under different domain names ( As there are multiple domains for different requests):

abc.domain.com-> cookie1,cookie2 ... etc
def.domain.com -> cookie1,cookie2 ..等

abc.domain.com -> cookie1, cookie2...etc def.domain.com -> cookie1, cookie2.. etc

,但在移动Cookie中,它们是针对相同的主机名存储的:

but in mobile cookies are stored against same hostname:

abc。 domain.com-> cookie1,cookie2 ... etc

abc.domain.com -> cookie1, cookie2...etc

更新:移动版时的标头不同。如果有帮助

任何帮助将不胜感激。

推荐答案

找到了解决方案。更改凭据以在Relayjs中共享跨域cookie:

Found the solution. Changed credentials to share cross domain cookies in relayjs:

Relay.injectNetworkLayer(
新的Relay.DefaultNetworkLayer(GQL_URL,{
凭据:包括,
})));

在台式机上,与移动设备相比,iframe的加载方式我们正在执行xhr请求并在此之后在div中插入内容的版本。
因此,在iframe的情况下,cookie会针对正确的域进行存储,因为来自正确的来源,但xhr的来源却保持不变。因此需要通过跨域Cookie进行访问。

In case of desktop, iframe was getting loaded in contrast to mobile version where we are doing xhr request and inserting content in div after that. So cookies were getting stored against correct domain in case of iframe because coming form correct origin but in case of xhr origin remains the same. So needed to acces through cross domain cookies.

感谢您的帮助!

这篇关于Cookie未通过RelayJS在graphql请求中的移动浏览器中传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆