8
8
namespace Magento \LoginAsCustomer \Plugin ;
9
9
10
10
use Magento \Backend \Model \Auth ;
11
+ use Magento \Backend \Model \Auth \Session as AuthSession ;
11
12
use Magento \LoginAsCustomerApi \Api \ConfigInterface ;
12
13
use Magento \LoginAsCustomerApi \Api \DeleteAuthenticationDataForUserInterface ;
13
14
16
17
*/
17
18
class AdminLogoutPlugin
18
19
{
20
+ /**
21
+ * @var AuthSession
22
+ */
23
+ private $ authSession ;
24
+
19
25
/**
20
26
* @var ConfigInterface
21
27
*/
@@ -27,13 +33,16 @@ class AdminLogoutPlugin
27
33
private $ deleteAuthenticationDataForUser ;
28
34
29
35
/**
36
+ * @param AuthSession $authSession
30
37
* @param ConfigInterface $config
31
38
* @param DeleteAuthenticationDataForUserInterface $deleteAuthenticationDataForUser
32
39
*/
33
40
public function __construct (
41
+ AuthSession $ authSession ,
34
42
ConfigInterface $ config ,
35
43
DeleteAuthenticationDataForUserInterface $ deleteAuthenticationDataForUser
36
44
) {
45
+ $ this ->authSession = $ authSession ;
37
46
$ this ->config = $ config ;
38
47
$ this ->deleteAuthenticationDataForUser = $ deleteAuthenticationDataForUser ;
39
48
}
@@ -46,7 +55,8 @@ public function __construct(
46
55
public function beforeLogout (Auth $ subject ): void
47
56
{
48
57
$ user = $ subject ->getUser ();
49
- if ($ this ->config ->isEnabled () && $ user && $ user ->getIsLoggedAsCustomer ()) {
58
+ $ isLoggedAsCustomer = $ this ->authSession ->getIsLoggedAsCustomer ();
59
+ if ($ this ->config ->isEnabled () && $ user && $ isLoggedAsCustomer ) {
50
60
$ userId = (int )$ user ->getId ();
51
61
$ this ->deleteAuthenticationDataForUser ->execute ($ userId );
52
62
}
0 commit comments