I auth state
This commit is contained in:
parent
76d6b30fdf
commit
dcf8315290
|
|
@ -134,7 +134,7 @@ class Handler implements MessageComponentInterface
|
|||
]));
|
||||
}
|
||||
|
||||
$this->authenticateConnection($connection, $channel, $message);
|
||||
$this->authenticateConnection($connection, $channel);
|
||||
|
||||
\Log::channel('websocket')->info('[' . $connection->socketId . ']@' . $channel->getName() . ' | ' . json_encode($message));
|
||||
|
||||
|
|
@ -150,6 +150,7 @@ class Handler implements MessageComponentInterface
|
|||
$pid = pcntl_fork();
|
||||
|
||||
if ($pid == -1) {
|
||||
Auth::logout();
|
||||
Log::error('Fork error');
|
||||
} elseif ($pid == 0) {
|
||||
try {
|
||||
|
|
@ -181,6 +182,7 @@ class Handler implements MessageComponentInterface
|
|||
|
||||
exit(0);
|
||||
} else {
|
||||
Auth::logout();
|
||||
$this->addDataCheckLoop($connection, $message, $pid);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
|
|
@ -190,6 +192,7 @@ class Handler implements MessageComponentInterface
|
|||
'trace' => $e->getTraceAsString(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -197,6 +200,8 @@ class Handler implements MessageComponentInterface
|
|||
*/
|
||||
public function onClose(ConnectionInterface $connection): void
|
||||
{
|
||||
$this->authenticateConnection($connection, null);
|
||||
|
||||
// remove connection from $channel_connections
|
||||
foreach ($this->channel_connections as $channel => $connections) {
|
||||
if (in_array($connection->socketId, $connections)) {
|
||||
|
|
@ -228,6 +233,10 @@ class Handler implements MessageComponentInterface
|
|||
$authed_users = cache()->get('ws_socket_authed_users') ?? [];
|
||||
unset($authed_users[$connection->socketId]);
|
||||
cache()->forever('ws_socket_authed_users', $authed_users);
|
||||
|
||||
\BlaxSoftware\LaravelWebSockets\Services\WebsocketService::clearUserAuthed(
|
||||
$connection->socketId
|
||||
);
|
||||
}
|
||||
|
||||
$this->channelManager
|
||||
|
|
@ -241,6 +250,8 @@ class Handler implements MessageComponentInterface
|
|||
cache()->forget('ws_connection_' . $connection->socketId);
|
||||
}
|
||||
});
|
||||
|
||||
Auth::logout();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -468,7 +479,6 @@ class Handler implements MessageComponentInterface
|
|||
protected function authenticateConnection(
|
||||
ConnectionInterface $connection,
|
||||
PrivateChannel|Channel|PresenceChannel|null $channel,
|
||||
$message
|
||||
) {
|
||||
|
||||
if (! optional($connection)->auth && $connection->socketId && cache()->get('socket_' . $connection->socketId)) {
|
||||
|
|
@ -477,13 +487,17 @@ class Handler implements MessageComponentInterface
|
|||
|
||||
$connection->user = @$cached_auth['type']::find($cached_auth['id']);
|
||||
|
||||
$channel->saveConnection($connection);
|
||||
if($channel){
|
||||
$channel->saveConnection($connection);
|
||||
}
|
||||
}
|
||||
|
||||
// Update last online of user if user
|
||||
if (! optional($connection)->user) {
|
||||
$connection->user = false;
|
||||
$channel->saveConnection($connection);
|
||||
if($channel){
|
||||
$channel->saveConnection($connection);
|
||||
}
|
||||
}
|
||||
|
||||
// Set auth or logout
|
||||
|
|
@ -506,6 +520,11 @@ class Handler implements MessageComponentInterface
|
|||
$authed_users[$connection->socketId] = $user->id;
|
||||
cache()->forever('ws_socket_authed_users', $authed_users);
|
||||
}
|
||||
|
||||
// add next in loop logout
|
||||
$this->channelManager->loop->futureTick(function () {
|
||||
Auth::logout();
|
||||
});
|
||||
}
|
||||
|
||||
private function addDataCheckLoop(
|
||||
|
|
|
|||
Loading…
Reference in New Issue