Search code examples
laravel-5.3laravel-echopusher-js

Laravel Echo + Pusher: request to broadcasting/auth returns login page


I updated my application from 5.2 to 5.3 to broadcast notifications with Pusher, but when pusher try to authenticate current logged in user over broadcasting/auth, I got an error:

Pusher : No callbacks on private-App.Models.Client.9 for pusher:subscription_error

in the browser console->network->xhr, I found that the request to broadcasting/auth not giving me the auth:{token} object, but returning my login page instead !!!

I think it is a problem with middleware but I can't find it.

BroadcastServiceProvider.php:

public function boot()
{
    // Broadcast::routes();
    Broadcast::routes(['middleware' => ['auth:client']]);

    /*
     * Authenticate the user's personal channel...
     */
    Broadcast::channel('App.Models.Client.*', function ($user, $userId) {
        return true;
    });

}

app.js: after importing pusher-js & Laravel Echo

$(document).ready(function() {
// check if there's a logged in user
if(Laravel.clientId) {
    window.Echo.private(`App.Models.Client.${Laravel.clientId}`)
        .notification((notification) => {
            console.log(notification);
            addNotifications([notification], '#notifications');
        });
} });

any help would be much appreciated!


Solution

  • After a long time of pulling my hair, I finally found the cause of this issue. I was using a package for Authentication/Authorization called cartalyst/sentinel which is great except that once installed it will entirely replace the Laravel default auth behavior. So any request to broadcasting/auth is actually rejected.