From 7b793ef393adee660064bf909ba21caddc2d0b32 Mon Sep 17 00:00:00 2001 From: erikn69 Date: Wed, 28 Feb 2024 10:33:43 -0500 Subject: [PATCH] Clear session on impersonation exception --- src/Services/ImpersonateManager.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Services/ImpersonateManager.php b/src/Services/ImpersonateManager.php index 5bdd05a..7b8b57c 100644 --- a/src/Services/ImpersonateManager.php +++ b/src/Services/ImpersonateManager.php @@ -112,6 +112,13 @@ public function take($from, $to, $guardName = null) $this->saveAuthCookieInSession(); try { + if ( + !method_exists($this->app['auth']->guard($currentGuard), 'quietLogout') + || !method_exists($this->app['auth']->guard($guardName), 'quietLogin') + ) { + return false; + } + $currentGuard = $this->getCurrentAuthGuardName(); session()->put($this->getSessionKey(), $from->getAuthIdentifier()); session()->put($this->getSessionGuard(), $currentGuard); @@ -122,6 +129,7 @@ public function take($from, $to, $guardName = null) } catch (\Exception $e) { unset($e); + $this->clear(); return false; }