diff --git a/src/utils/echo/initEcho.js b/src/utils/echo/initEcho.js index 9d27b37..4e59d4b 100644 --- a/src/utils/echo/initEcho.js +++ b/src/utils/echo/initEcho.js @@ -14,8 +14,31 @@ export default function initEcho() { encrypted: import.meta.env.VITE_ENCRYPTED === 'true', cluster: import.meta.env.VITE_CLUSTER, enabledTransports: ['ws', 'wss'], + authorizer: (channel) => { + return { + authorize: (socketId, callback) => { + fetch(`${import.meta.env.VITE_API_URL}/broadcasting/auth`, { + method: 'POST', + credentials: 'include', + headers: { + 'Content-Type': 'application/json', + 'X-Requested-With': 'XMLHttpRequest', + }, + body: JSON.stringify({ + socket_id: socketId, + channel_name: channel.name, + }), + }) + .then(res => res.json()) + .then(data => callback(null, data)) + .catch(err => callback(err, null)); + }, + }; + }, }); + + window.Echo = echoInstance; return echoInstance; }