Reactivesearch proxylike backend with cookie authentication

一笑奈何 提交于 2019-12-06 16:10:40

Okey so it turns out, Reactivesearch uses fetch and fetch wants credentials: 'include' for cookie authentication. This may not be placed in the headers that Reactivesearch supplies and must be placed on the root object for the request.

It's possible to do this by implementing beforeSend on ReactiveBase.

const Base = ({ children }) => {
  const onBeforeSend = props => {
    return {
      ...props,
      credentials: 'include',
    }
  }

  return (
    <ReactiveBase
      app="app-name"
      url="url"
      beforeSend={onBeforeSend}
    >
      {children}
    </ReactiveBase>
  )
}

You can use the headers prop in ReactiveBase to pass custom headers along with the requests. Link to docs. Since there is no withCredentials you could read the cookies and set in custom headers to verify the requests at the proxy middleware.

<ReactiveBase
  ...
  headers={{
      customheader: 'abcxyz'
  }}
>
    <Component1 .. />
    <Component2 .. />
</ReactiveBase>

Here is a sample proxy server but its in NodeJS

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