1

I have a created a notification system with all setup and its working fine when i send notification to pusher. But when I try to listen on private channel I get error.

Here is my bootstrap.js file laravel-echo code

    import Echo from 'laravel-echo';

    window.Pusher = require('pusher-js');
    let token = document.head.querySelector('meta[name="csrf-token"]').content;
    window.Echo = new Echo({
        broadcaster: 'pusher',
        key: process.env.MIX_PUSHER_APP_KEY,
        cluster: process.env.MIX_PUSHER_APP_CLUSTER,
        forceTLS: true,
            auth: {
            headers: {
              'X-CSRF-Token': token
            }
          }
      
    });

Here is my meta tag content of main html

 <meta name="csrf-token" content="{{ csrf_token() }}">
 <meta name="user-id" content="{{Auth::check() ? Auth::user()->api_token:''}}">

Here is the code to listen in app.js

let userId = document.head.querySelector('meta[name="user-id"]').content;
Echo.private('App.User.' + userId)
    .notification((notification) => {
        console.log(notification.type);
    });

Here is the error i am getting on console

POST http://localhost:3000/broadcasting/auth 419 (unknown status)

Thanks in advance

Pashupati Sah
  • 426
  • 5
  • 9

2 Answers2

0

Error code 419 is used by Laravel to indicate your CSRF token is either invalid or missing. You should ensure you are passing the correct token to your auth endpoint.

doydoy
  • 4,021
  • 3
  • 20
  • 33
0

I figured it out. It was an issue due to route setup in BroadcastServiceProvider.php

Pashupati Sah
  • 426
  • 5
  • 9