【问题标题】:POST http://localhost:8000/broadcasting/auth 403 (Forbidden) / for customer service chat where i only need auth for adminsPOST http://localhost:8000/broadcasting/auth 403(禁止)/用于客户服务聊天,我只需要管理员身份验证
【发布时间】:2019-12-31 10:05:53
【问题描述】:

我如何为管理员使用广播/身份验证但对普通用户不使用,并且仍然可以互相聊天?

// 广播服务提供者

public function boot()
{

    Broadcast::routes();

    require base_path('routes/channels.php');
}

// Channels.php

Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id; });

Broadcast::channel('chat', function ($user) {
return $user;  });

// 消息发送事件

public function broadcastOn()
{
    return new PresenceChannel('chat');
}

我收到此错误:POST http://localhost:8000/broadcasting/auth 403 (Forbidden),但是当我从 laravel echo (Echo.join('chat')) 中删除时,错误消失了。

【问题讨论】:

    标签: laravel authentication chat broadcast


    【解决方案1】:

    你可以在 laravel 中使用 Middleware 来实现这样的事情。

    此引用来自laravel官网:

    中间件提供了一种方便的机制来过滤 HTTP 请求 输入您的应用程序。例如,Laravel 包含一个中间件 验证您的应用程序的用户是否已通过身份验证。如果 用户未通过身份验证,中间件会将用户重定向到 登录屏幕。但是,如果用户通过了身份验证,则 中间件将允许请求进一步进入 应用。

    完整阅读此website

    【讨论】:

    • 谢谢!从网站上阅读后,我能够使用中间件找到与我的问题类似的内容
    猜你喜欢
    • 2018-05-18
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多