Framework: Laravel Echo Private Channel Authentication

Created on 18 Sep 2016  路  4Comments  路  Source: laravel/framework

  • Laravel Version: 5.3
  • PHP Version: 7
  • Database Driver & Version: Mysql

    Description:

In my application i have two separated sections for users and admins which i used Auth::guard() to authenticate them.

in my dashboard (admin guard) i used Laravel Echo (pusher) to show live notifications. echo tries to authenticate for incoming messages automatically by sending an XHR request to /broadcasting/auth, and it fails, because in PusherBroadcasting.php line 38 you check for authenticated user in request.

the problem is that my dashboard is using token header to send xhr requests to my controllers, and i have my own middleware to check for that. so. as you can see there is no user at $request->user().

i had to remove line 38-42 in order to fix this problem temporarily.

Most helpful comment

You can pass route parameters to the broadcasting routes:

Broadcast::routes(['middleware' => ['web', 'myMiddleware']]);

All 4 comments

You can pass route parameters to the broadcasting routes:

Broadcast::routes(['middleware' => ['web', 'myMiddleware']]);

thanks! but when i want to use it it triggers this error:
Class App\Http\Controllers\Illuminate\Broadcasting\BroadcastController does not exist.

is it possible to change authenticated user for reach guard? i need App\Admin to be logged in for my admin section and App\User for my user panel. is it possible with your solution?

You have to put Broadcast::routes(); into the api.php routes file.

getting error

Class App\Http\Controllers\Illuminate\Broadcasting\BroadcastController does not exist

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Anahkiasen picture Anahkiasen  路  3Comments

JamborJan picture JamborJan  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

jackmu95 picture jackmu95  路  3Comments

felixsanz picture felixsanz  路  3Comments