Laravel Echo Server can not be authenticated, got HTTP status 500

1.9k views Asked by At

I've installed both Laravel echo server and Laravel echo client.

Following is the laravel-echo-server.json configuration.

{
"authHost": "http://taxation.com",
"authEndpoint": "/broadcasting/auth",
"clients": [
    {
        "appId": "APP_ID",
        "key": "someKey"
    }
],
"database": "redis",
"databaseConfig": {
    "redis": {},
    "sqlite": {
        "databasePath": "/database/laravel-echo-server.sqlite"
    }
},
"devMode": true,
"host": "127.0.0.1",
"port": "3000",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": ""
}

The following script listens for channel events. It builds fine with npm run dev.

import Echo from 'laravel-echo'
let token = document.head.querySelector('meta[name="token"]');
if (token) {
    window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
    console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: '127.0.0.1:3000',
    reconnectionAttempts: 5
});


window.Echo.join('checked-in-1')
            .listen('.user.checked_in', (e) => {
            console.log(e);
        });

When trying to listen for any event on start laravel-echo-server command. It keeps throwing Client can not be authenticated, got HTTP status 500.

Note :

I really didn't find anything helpful on laravel-echo-serve nor on google.

Any help will be appreciated a lot.

Laravel V5.4

Thanks

1

There are 1 answers

0
Basheer Kharoti On BEST ANSWER

Just getting the issue because of CSRF token. Didn't passed the token to the echo.

window.Echo = new Echo({
    broadcaster: 'socket.io',
    host: '127.0.0.1:3000',
    reconnectionAttempts: 5,
    csrfToken: token.content <--
});