Magento 2: How to terminate other admin session in backend?
-
25-12-2020 - |
Question
How to terminate other administrator session in back-end
Solution
Simple we can get $sessionInfo \Magento\Security\Model\AdminSessionInfo */ and set status 0 for which $sessionId we want to terminate
public function destroySession($sessionId)
{
/** @var $sessionInfo \Magento\Security\Model\AdminSessionInfo */
$sessionInfo = $this->adminSessionInfoFactory->create()->load($sessionId, 'session_id');
try{
$sessionInfo->getResource()->updateStatusByUserId(
\Magento\Security\Model\AdminSessionInfo::LOGGED_OUT,
$sessionInfo->getUserId(),
[1],
[],
null
);
} catch (\Exception $e) {
}
return $this;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange