Skip to content

Commit 7b793ef

Browse files
committed
Clear session on impersonation exception
1 parent d8ab69f commit 7b793ef

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/Services/ImpersonateManager.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ public function take($from, $to, $guardName = null)
112112
$this->saveAuthCookieInSession();
113113

114114
try {
115+
if (
116+
!method_exists($this->app['auth']->guard($currentGuard), 'quietLogout')
117+
|| !method_exists($this->app['auth']->guard($guardName), 'quietLogin')
118+
) {
119+
return false;
120+
}
121+
115122
$currentGuard = $this->getCurrentAuthGuardName();
116123
session()->put($this->getSessionKey(), $from->getAuthIdentifier());
117124
session()->put($this->getSessionGuard(), $currentGuard);
@@ -122,6 +129,7 @@ public function take($from, $to, $guardName = null)
122129

123130
} catch (\Exception $e) {
124131
unset($e);
132+
$this->clear();
125133
return false;
126134
}
127135

0 commit comments

Comments
 (0)