无法从身份验证端点检索身份验证字符串 - 接收状态:500

Unable to retrieve auth string from auth endpoint - received status: 500

我使用 React Native 和后端 node.I 尝试在我的应用程序中实施推送器。

Object {
  "error": "Unable to retrieve auth string from auth endpoint - received status: 0 from http://10.0.27.124:8070/pusher/auth. Clients must be authenticated to join private or presence channels. See: https://pusher.com/docs/authenticating_users",
  "status": 0,
  "type": "AuthError",
}

这是我的本机反应代码:

  const pusher = new Pusher('73286f08a5b2aeeea398', {
    cluster: 'ap1',
    authEndpoint: 'http://10.0.27.124:8070/pusher/auth',
  });
  console.log(pusher)
  const presenceChannel = pusher.subscribe('presence-channel');

这是我的节点 js 代码:

exports.authPusher = function (req, res) {
  const socketId = req.body.socket_id;
  const channel = req.body.channel_name;
  console.log(req.body);

  const presenceData = {
    user_id: 'unique_user_id',
    user_info: { name: 'Mr Channels', twitter_id: '@pusher' },
  };
  const auth = pusher.authenticate(socketId, channel, presenceData);
  res.send(auth);
};

感谢您的回答。

我想你只是忘了在 authEndpoint 参数周围使用引号。 Pusher 正在尝试调用 http 而不是 http://10.0.27.124:8070/pusher/auth.

const pusher = new Pusher('73286f08a5b2aeeea398', {
  cluster: 'ap1',
  authEndpoint: 'http://10.0.27.124:8070/pusher/auth',
});

如果您在浏览器的网络开发人员工具栏上打开网络选项卡,您必须能够看到实际请求并从那里进行调试。