Magento 2 – How to Fix Admin Session Issue to Login to Admin Panel

adminmagento2session

After upgrading my Magento 2 I see this error message all the time I try to log in via the admin panel. The frontend pages are working fine.

Fatal error: Uncaught TypeError: strtotime() expects parameter 1 to be string, null given in /app/vendor/magento/module-security/Model/AdminSessionInfo.php:136 Stack trace: 
#0 /app/vendor/magento/module-security/Model/AdminSessionInfo.php(136): strtotime(NULL) 
#1 /app/vendor/magento/module-security/Model/AdminSessionInfo.php(119): Magento\Security\Model\AdminSessionInfo->isSessionExpired() 
#2 /app/vendor/magento/module-security/Model/AdminSessionInfo.php(108): Magento\Security\Model\AdminSessionInfo->checkActivity() 
#3 /app/vendor/magento/module-security/Model/Plugin/AuthSession.php(63): Magento\Security\Model\AdminSessionInfo->isLoggedInStatus() 

#4 /app/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Security\Model\Plugin\AuthSession->aroundProlong(Object(Magento\Backend\Model\Auth\Session\Interceptor), Object(Closure)) 
#5 /app/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Backend\Model\Auth\Session\Interceptor->Magento\Framework\Interception\{closure}() 
#6 /app/generated/code/Ma in /app/vendor/magento/module-security/Model/AdminSessionInfo.php on line 136

How could I solve it?

Best Answer

issue in vendor/magento/module-security/Model/AdminSessionInfo.php you need to replace this

public function isSessionExpired()
{
$lifetime = $this->securityConfig->getAdminSessionLifetime();
$currentTime = $this->dateTime->gmtTimestamp();
$lastUpdatedTime = $this->getUpdatedAt();
if (!is_numeric($lastUpdatedTime)) {
    $lastUpdatedTime = strtotime($lastUpdatedTime);
}
return $lastUpdatedTime <= ($currentTime - $lifetime) ? true : false;
}

with

public function isSessionExpired()
{
$lifetime = $this->securityConfig->getAdminSessionLifetime();
$currentTime = $this->dateTime->gmtTimestamp();
$lastUpdatedTime = $this->getUpdatedAt();
if (!is_numeric($lastUpdatedTime)) {
    $lastUpdatedTime = $lastUpdatedTime === null ? 0 : strtotime($lastUpdatedTime);
}
return $lastUpdatedTime <= ($currentTime - $lifetime);
}
Related Topic