From 80769a0b65bb1862e9d79bbd284d54e8505a66ec Mon Sep 17 00:00:00 2001 From: Steven Nguyen <1477010+stnguyen90@users.noreply.github.com> Date: Fri, 19 Jul 2024 00:06:14 +0000 Subject: [PATCH] fix(realtime): unsubscribe before resubscribing on permission change Unsubcribe to remove subscriptions related to the old permissions. --- app/realtime.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/realtime.php b/app/realtime.php index 28e6c1691f..9c3c2b4d6a 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -380,8 +380,10 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, $user = $database->getDocument('users', $userId); $roles = Auth::getRoles($user); + $channels = $realtime->connections[$connection]['channels']; - $realtime->subscribe($projectId, $connection, $roles, $realtime->connections[$connection]['channels']); + $realtime->unsubscribe($connection); + $realtime->subscribe($projectId, $connection, $roles, $channels); $register->get('pools')->reclaim(); }