Magento 2 : How to end all active sessions for a customer?
-
12-03-2021 - |
문제
I was looking for possibility where i can give option to customer after password update to end all active sessions related to his account .
It would be helpful if can point in direction (even with a article link)
해결책
I've found one post, hope it is helpful for you.
You'll have to create a custom module for that in my opinion. In that module you,
Create a customer attribute
login_expiry
, whose value is initially null.Add a new value to the
customer_session
by calling the\Magento\Customer\Model\Session::setData($name, $value)
method, calledlogged_in_at
.Write an observer for the
customer_login
event and set thelogged_in_at
value to the current timestamp.Whenever user opts for "logout from all devices", set the
login_expiry
value of that customer to the current timestamp.Write an observer for the
customer_session_init
event and there check if thelogged_in_at
value is less thanlogin_expiry
, logout the user.