From 959b5e3596091f73260f46fd2fc6543fa9dea55f Mon Sep 17 00:00:00 2001 From: nickpons666 Date: Sat, 31 Jan 2026 02:12:51 -0600 Subject: [PATCH] =?UTF-8?q?Implementaci=C3=B3n=20de=20actualizaci=C3=B3n?= =?UTF-8?q?=20instant=C3=A1nea=20de=20roles=20sin=20cierre=20de=20sesi?= =?UTF-8?q?=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Auth.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Auth.php b/src/Auth.php index ad3d58c..048a4d6 100755 --- a/src/Auth.php +++ b/src/Auth.php @@ -10,6 +10,31 @@ class Auth { public function __construct() { $this->userModel = new User(); Session::init(); + $this->refreshUserSession(); + } + + /** + * Refresca los datos del usuario en la sesión directamente desde la base de datos + * para que los cambios de rol sean instantáneos. + */ + private function refreshUserSession() { + if ($this->isLoggedIn()) { + $userId = Session::get('user_id'); + $user = $this->userModel->getById($userId); + + if (!$user || (isset($user['activo']) && !$user['activo'])) { + $this->logout(); + return; + } + + // Actualizar solo si hay cambios para evitar escrituras innecesarias en la sesión + if (Session::get('user_rol') !== $user['rol']) { + Session::set('user_rol', $user['rol']); + } + if (Session::get('user_name') !== $user['nombre']) { + Session::set('user_name', $user['nombre']); + } + } } public function login($login, $password) {