Answer the question
In order to leave comments, you need to log in
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']]);
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 = {};
}
async created() {
const channel = pusher.subscribe('private-platform-import');
channel.bind('platform-import-created', (data) => {
console.log(data);
});
},
beforeDestroy() {
pusher.unsubscribe('private-platform-import');
},
Broadcast::channel('user.{userId}', function ($user, $userId) {
return $user->id === $userId;
});
Broadcast::channel('platform-import', function () {
return Auth::user()->role === 'admin';
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question