I’m receiving the Error joining the channel: {"error": undefined, "type": "AuthError"}
when I try to join a private channel. Another error message I’ve encountered with different setups is:
Error joining the channel: {"error": "Unable to retrieve auth string from channel-authorization endpoint - received status: 0 from /broadcasting/auth. Clients must be authorized to join private or presence channels. See: https://pusher.com/docs/channels/server_api/authorizing-users/", "status": 0, "type": "AuthError"}
This is the current setup I have:
channels.php
:
Broadcast::channel('example.request.{search_token}', function ($user, $search_token) {
return $user->search_token === $search_token;
}, ['middleware' => ['auth:sanctum']]);
Echo setup in react native:
import Echo from 'laravel-echo';
import Pusher from 'pusher-js';
export default function Overview() {
const token = userTokenStore((state) => state.token);
const channels = new Echo({
broadcaster: 'reverb',
Pusher,
key: 'pbvxccih2ntq3i2zhonj',
wsHost: '0.0.0.0',
wsPort: '8080',
wssPort: '8080' ?? 443,
forceTLS: ('http' ?? 'https') === 'https',
enabledTransports: ['ws', 'wss'],
authorizer: (channel, options) => {
return {
authorize: (socketId, callback) => {
axios.post('/api/broadcasting/auth', {
socket_id: socketId,
channel_name: channel.name
}, {
headers: {
'Authorization': `Bearer ${token}`
}
})
.then(response => {
callback(false, response.data);
})
.catch(error => {
callback(true, error);
});
}
};
},
});
...
And then we join the private channel:
useEffect(() => {
channels.private(`example.request.${search_token}`)
.listen('StartExampleRequest', async (e) => {
console.log('Received request:', e);
Toast.show({
type: 'info',
text1: 'Debugging toast',
text2: 'You have a new request'
});
})
.error((error) => {
console.log('Error joining the channel:', error);
});
}, [])
It’s quite puzzling why it doesn’t work. It does join to public channels, but not to private channels.