Corepine logo Corepine Wirechat
Wirechat v0.6x latest

Authorization

Panels configure the guards and middleware Wirechat uses for panel routes, conversation routes, and private broadcasting channels.

Guards

Guards determine how users are authenticated for each request. Configure the panel with the same guard names your application uses for the authenticated chat area.

Default Guard Setup

A panel can define a single guard:

use Wirechat\Wirechat\Panel;

public function panel(Panel $panel): Panel
{
    return $panel
            //..
            ->guards(['web']);
}

No additional setup is needed if you are using the default web guard.

Using Multiple Guards

If your application uses multiple guards, such as admin and web, you can chain them in the panel:

use Wirechat\Wirechat\Panel;

public function panel(Panel $panel): Panel
{
    return $panel
            //..
            ->guards(['web', 'admin']);
}

Users authenticated through any listed guard can access the panel routes and private channels.


Middleware

Middleware runs when users access panel routes such as /chats and conversation routes such as /chats/{conversation}.

Default Middleware Setup

Panel middleware wraps the panel's main routes:

use Wirechat\Wirechat\Panel;

public function panel(Panel $panel): Panel
{
    return $panel
            //..
            ->middleware(['web', 'auth']);
}

Multi-Guard Authentication

For multiple guards, make the authentication middleware accept the same guard list:

use Wirechat\Wirechat\Panel;

public function panel(Panel $panel): Panel
{
    return $panel
            //..
            ->middleware(['web', 'auth:admin,web'])
            ->guards(['web', 'admin']);
}

Chat Middleware

Wirechat applies belongsToConversation to the default /chats/{conversation} route so only participants can open a conversation.

Register additional conversation-route middleware with chatMiddleware():

use Wirechat\Wirechat\Panel;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->chatMiddleware([
            // Your custom middleware
        ]);
}

Using the belongsToConversation Middleware

Custom routes that render a single chat component directly must apply the same conversation middleware before the component is mounted:

use Illuminate\Support\Facades\Route;
use Wirechat\Wirechat\Models\Conversation;

Route::get('/support/chat/{conversation}', function (Conversation $conversation) {
    return view('support.chat', ['conversation' => $conversation]);
})->middleware(['web', 'auth', 'belongsToConversation']);

Then in Blade:

<livewire:wirechat.chat :conversation="$conversation" />

The middleware keeps the custom route aligned with Wirechat's default conversation access rule.


Broadcasting Middleware Configuration

Match your broadcasting route guards and middleware to the panel configuration:

// app/Providers/BroadcastServiceProvider.php

Broadcast::routes([
    'middleware' => ['web', 'auth:admin,web'],
    'guards' => ['web', 'admin'],
]);

If these values drift apart, users can be authenticated for a panel route but rejected when they subscribe to a private channel.