markpmark
markpmark

Reputation: 61

Laravel private channel authorization not working

I am learning pusher to use it with Laravel, I am trying to subscribe to private channel using Laravel-echo as follow:

import Echo from 'laravel-echo';

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    Pusher.logToConsole = true; //update: added this
    broadcaster: 'pusher',
    key: process.env.MIX_PUSHER_APP_KEY,
    cluster: process.env.MIX_PUSHER_APP_CLUSTER,
    encrypted: true
});

var channel = window.Echo.private('roomr');

and per Laravel documentations I have to set authorization in channel.php file so in I wrote in it:

Broadcast::channel('roomr', function ($user) {
    logger('hit authorize roomr');
    return true;
});

please note that I used logger('hit authorize roomr'); to know if my function is being called, but, when I check the log file it is empty which means that this function is not being called.

using developer tools in google chrome I see there is a post request sent to http://127.0.0.1:8000/broadcasting/auth which return response 200, so, I do not think the authentication is the problem.

Update:

after I added Pusher.logToConsole = true; to my javascript now in chrome console I get:

Pusher : : ["JSON returned from auth endpoint was invalid, yet status code was 200. Data was: "]

what else I can do? please help me to solve this probem

Upvotes: 2

Views: 1212

Answers (1)

markpmark
markpmark

Reputation: 61

The problem was in the .env file and I solved it by setting BROADCAST_DRIVER=pusher

Upvotes: 4

Related Questions