Skip to content

Commit 8dc6b6f

Browse files
committed
magento-commerce/magento2-login-as-customer#171: Force customer unlogin during admin loglout without additional MySQL queries
1 parent abfce98 commit 8dc6b6f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ public function __construct(
4545
*/
4646
public function beforeLogout(Auth $subject): void
4747
{
48-
if ($this->config->isEnabled() && $subject->getUser()) {
49-
$userId = (int)$subject->getUser()->getId();
48+
$user = $subject->getUser();
49+
if ($this->config->isEnabled() && $user && $user->getIsLoggedAsCustomer()) {
50+
$userId = (int)$user->getId();
5051
$this->deleteAuthenticationDataForUser->execute($userId);
5152
}
5253
}

app/code/Magento/LoginAsCustomer/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313
<preference for="Magento\LoginAsCustomerApi\Api\DeleteAuthenticationDataForUserInterface" type="Magento\LoginAsCustomer\Model\ResourceModel\DeleteAuthenticationDataForUser"/>
1414
<preference for="Magento\LoginAsCustomerApi\Api\ConfigInterface" type="Magento\LoginAsCustomer\Model\Config"/>
1515
<preference for="Magento\LoginAsCustomerApi\Api\IsLoginAsCustomerSessionActiveInterface" type="Magento\LoginAsCustomer\Model\ResourceModel\IsLoginAsCustomerSessionActive"/>
16+
<type name="Magento\Backend\Model\Auth">
17+
<plugin name="login_as_customer_admin_logout" type="Magento\LoginAsCustomer\Plugin\AdminLogoutPlugin"/>
18+
</type>
1619
</config>

0 commit comments

Comments
 (0)