Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.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
React native 使用React Native中的ActionCable发送标头中的参数_React Native_Authentication_Header_Chat_Actioncable - Fatal编程技术网

React native 使用React Native中的ActionCable发送标头中的参数

React native 使用React Native中的ActionCable发送标头中的参数,react-native,authentication,header,chat,actioncable,React Native,Authentication,Header,Chat,Actioncable,我一直在尝试创建一个聊天电缆和频道。我在react native中工作,正在使用Ruby on Rails制作的后端,该后端在头参数中需要我的uid: def find_verified_user # this checks whether a user is authenticated with devise User.find_by(uid: request.headers['HTTP_AUTHORIZATION']) || reject_unauthorized_connection

我一直在尝试创建一个聊天电缆和频道。我在react native中工作,正在使用Ruby on Rails制作的后端,该后端在头参数中需要我的uid:

def find_verified_user # this checks whether a user is authenticated with devise
  User.find_by(uid: request.headers['HTTP_AUTHORIZATION']) || reject_unauthorized_connection
end
发生的事情是我陷入了拒绝未经授权的连接

我想弄清楚的是,当我创建电缆时,如何发送我的头

我在谷歌上搜索了一下这里,大多数答案都说这是不可能的,但它们是2016年或2017年的,所以现在可能吗?我看到的解决方案是将url中的参数作为queryparams,但在这种情况下,我需要更改我的后端api,所以我想知道是否有其他解决方案不必更改后端

我正在使用“ActionCable”中的ActionCable

我曾尝试使用“react native action cable jwt”中的ActionCable jwt,但要么我做错了什么,要么对我的情况没有帮助

提前谢谢。感谢您的帮助

编辑:显示一些操作电缆代码:

import { Platform } from 'react-native';
import ActionCable from 'actioncable';

import { ANDROID, IOS } from 'constants/common';

ActionCable.getConfig = () => null;

ActionCable.createWebSocketURL = url => url.replace(/^http/, 'ws');

const oldOpen = ActionCable.Connection.prototype.open;
ActionCable.Connection.prototype.open = function open() {
  const result = oldOpen.apply(this);
  this.webSocket.protocol = 'actioncable-v1-json';
  return result;
};

if (Platform.OS === IOS || Platform.OS === ANDROID) {
  global.document = {
    addEventListener() {},
    removeEventListener() {},
  };
}

export default ActionCable;
当我使用它时(现在使用查询参数而不是标题):


分享actioncableHi的RN代码!对不起,这几个星期很复杂。最后,我只是更改了后端并在URL查询参数中接受用户信息,而不是使用标题或cookie。我仍然有兴趣知道是否有可能这样做,与标题。
  import actionCable from './actionCable';
  import { applyQueryParams } from 'utils/helpers';

  let cable = null;

  return store => next => action => {
    switch (action.type) {
      case createConsumer.toString(): {
        cable?.disconnect();
        const { uid } = action.payload;
        const queryParams = {
          uid,
        };

        cable = actionCable.createConsumer(
          applyQueryParams(Config.CABLE_URL, queryParams),
        );