Skip to content

Commit 1d300ba

Browse files
magento-commerce/magento2-login-as-customer#171: Force customer unlogin during admin loglout without additional MySQL queries.
1 parent 229f045 commit 1d300ba

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

app/code/Magento/LoginAsCustomer/Plugin/AdminLogoutPlugin.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\LoginAsCustomer\Plugin;
99

1010
use Magento\Backend\Model\Auth;
11+
use Magento\Backend\Model\Auth\Session as AuthSession;
1112
use Magento\LoginAsCustomerApi\Api\ConfigInterface;
1213
use Magento\LoginAsCustomerApi\Api\DeleteAuthenticationDataForUserInterface;
1314

@@ -16,6 +17,11 @@
1617
*/
1718
class AdminLogoutPlugin
1819
{
20+
/**
21+
* @var AuthSession
22+
*/
23+
private $authSession;
24+
1925
/**
2026
* @var ConfigInterface
2127
*/
@@ -27,13 +33,16 @@ class AdminLogoutPlugin
2733
private $deleteAuthenticationDataForUser;
2834

2935
/**
36+
* @param AuthSession $authSession
3037
* @param ConfigInterface $config
3138
* @param DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser
3239
*/
3340
public function __construct(
41+
AuthSession $authSession,
3442
ConfigInterface $config,
3543
DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser
3644
) {
45+
$this->authSession = $authSession;
3746
$this->config = $config;
3847
$this->deleteAuthenticationDataForUser = $deleteAuthenticationDataForUser;
3948
}
@@ -46,7 +55,8 @@ public function __construct(
4655
public function beforeLogout(Auth $subject): void
4756
{
4857
$user = $subject->getUser();
49-
if ($this->config->isEnabled() && $user && $user->getIsLoggedAsCustomer()) {
58+
$isLoggedAsCustomer = $this->authSession->getIsLoggedAsCustomer();
59+
if ($this->config->isEnabled() && $user && $isLoggedAsCustomer) {
5060
$userId = (int)$user->getId();
5161
$this->deleteAuthenticationDataForUser->execute($userId);
5262
}

app/code/Magento/LoginAsCustomerAdminUi/Controller/Adminhtml/Login/Login.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public function execute(): ResultInterface
167167

168168
$this->deleteAuthenticationDataForUser->execute($userId);
169169
$secret = $this->saveAuthenticationData->execute($authenticationData);
170+
$this->authSession->setIsLoggedAsCustomer(true);
170171

171172
$redirectUrl = $this->getLoginProceedRedirectUrl($secret, $storeId);
172173
$resultRedirect->setUrl($redirectUrl);

0 commit comments

Comments
 (0)