Send a Cookie header field in relay request

心不动则不痛 提交于 2019-12-06 09:51:14

问题


It looks like stock relay networklayer does'nt send a cookie header field with his request. So I tried to add it by adding Cookie field like this:

Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer('/graphql', {
    headers: {
      'Cookie': 'user=thibaut',
    },
  })
);

but still the Cookie field is not present in my post request. If I replace 'Cookie' with 'Set-Cookie', IT IS in my post request...

I need my server to use cookies please help ! :)


回答1:


Set your cookies in the usual way (using browser APIs) then configure fetch as follows to have them sent along with each request:

Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer('/graphql', {
    credentials: 'same-origin',
  })
);

See also: https://github.com/facebook/relay/issues/437



来源:https://stackoverflow.com/questions/32889938/send-a-cookie-header-field-in-relay-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!