Laravel Echo Auth 请求未在标头中发送 Cookie

问题描述 投票:0回答:1

我的客户端 laravel-echo 没有在标头中发送 cookie 参数,braodcasting/auth 需要标头中的 cookie 来授权 websocket 连接,当我尝试使用 fetch 发送相同的请求时,它可以工作,但当涉及我的 laravel echo 时却不行,怎么办我在标头中发送 cookie 参数 我尝试了一些技巧,但没有成功。

    window.Echo = new Echo({
      broadcaster: 'reverb',
      wsHost: 'localhost',
      key: 'yn0yitpyoptuuqiyjrhm',
      wsPort: 8080,
      wssPort: 8080,
      forceTLS: false,
       authEndpoint: 'http://localhost:8000/broadcasting/auth',
        headers: {
          Authorization: `Bearer ${token}`,
          Cookie: cookies,
        },
      withCredentials: true,
      enabledTransports: ['ws', 'wss'],
    });
reactjs laravel laravel-echo laravel-11 laravel-reverb
1个回答
0
投票

可能有任何可能的原因。请检查并配置以下内容。

  1. 确保您在中正确设置了广播配置
    *config/broadcasting.php*
    &
    *config/app.php*
    .
  2. 确保广播驱动程序(即推送器、redis 等)已设置且正确 在
    *config/broadcasting.php*
    &
    .env
    文件中配置。
  3. 确保
    routes/channel.php
    文件包含所需的通道路由 用于操作。
© www.soinside.com 2019 - 2024. All rights reserved.