D
D
Dmitriy2020-10-16 14:33:19
Laravel
Dmitriy, 2020-10-16 14:33:19

Error 404 Not found /broadcasting/auth Pusher?

I do SPA.

Setting up broadcasting.

I uncommented Broadcast classes in config/app.php,
added to BroadcastServiceProvider:

Broadcast::routes(['middleware' => ['admin', 'auth:api']]);


Pusher config on the front:
import Pusher from 'pusher-js';

const config = {
    authEndpoint: process.env.VUE_APP_PUSHER_APP_AUTH_ENDPOINT,
    cluster: process.env.VUE_APP_PUSHER_APP_CLUSTER,
    forceTLS: true,
    auth: {
        headers: {}
    }
};
if (localStorage.getItem('auth.accessToken')) {
    config.auth.headers = {
        Authorization: `Bearer ${localStorage.getItem('auth.accessToken')}`
    }
}

export const pusher = new Pusher(process.env.VUE_APP_PUSHER_APP_KEY, config);

export const updateSocketAuthToken = (accessToken) => {
    pusher.config.auth.headers.Authorization =
        `Bearer ${accessToken}`;
};

export const removeSocketAuthToken = () => {
    pusher.config.auth.headers = {};
}


This is how I call Pusher in the component:
async created() {
        const channel = pusher.subscribe('private-platform-import');
        channel.bind('platform-import-created', (data) => {
            console.log(data);
        });
    },
    beforeDestroy() {
        pusher.unsubscribe('private-platform-import');
    },


routes/channels.php
Broadcast::channel('user.{userId}', function ($user, $userId) {
    return $user->id === $userId;
});

Broadcast::channel('platform-import', function () {
    return Auth::user()->role === 'admin';
});

But it gives me an error:
POST guest-poster/api/v1/broadcasting/auth 404 (Not Found)

What could be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yvm, 2020-11-12
@yvm

Need to uncomment // App\Providers\BroadcastServiceProvider::class,
in config/app.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question