Skip to content

Commit 34eb852

Browse files
authored
Fix presence channel authentication
1 parent 7141005 commit 34eb852

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/AsyncClient.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ public function channel(string $channel): Observable
142142

143143
$subscribe = $this->connected
144144
->do(function (Event $event) use ($channel): void {
145-
$authKey = null;
145+
$authKey = $channelData = null;
146146

147147
if (str_starts_with($channel, 'private-') || str_starts_with($channel, 'presence-')) {
148-
$authKey = $this->generateAuthToken($channel, $event->getData()['socket_id']);
148+
[$authKey, $channelData] = $this->generateAuthToken($channel, $event->getData()['socket_id']);
149149
}
150150

151151
// Subscribe to pusher channel after connected
152-
$this->send(Event::subscribeOn($channel, $authKey));
152+
$this->send(Event::subscribeOn($channel, $authKey, $channelData));
153153
})
154154
->flatMapTo(Observable::empty());
155155

@@ -265,7 +265,7 @@ private function handleLowLevelError(Throwable $throwable): Observable
265265
/**
266266
* @throws \Exception
267267
*/
268-
private function generateAuthToken(string $channel, string $socketId): string
268+
private function generateAuthToken(string $channel, string $socketId): array
269269
{
270270
if (!$this->authEndpoint) {
271271
throw new \Exception('No auth endpoint is configured to connect private or presence channel.');
@@ -299,6 +299,6 @@ private function generateAuthToken(string $channel, string $socketId): string
299299
throw new \Exception('Invalid response for auth token.');
300300
}
301301

302-
return $response['auth'];
302+
return [$response['auth'], $response['channel_data'] ?? null];
303303
}
304304
}

0 commit comments

Comments
 (0)