While developing in Magento 2 after a while i get the following error:

Fatal error: Call to a member function getUsername() on null in /home/magento2/domains/../public_html/magento2/vendor/magento/module-backend/view/adminhtml/templates/page/header.phtml on line 32

I think it is after about 10 ~ 15 minutes. I need to relogin to proceed. What is the problem here and how can I solve it?

1 Answer 1


It seems you extends \Magento\Framework\App\Action\Action class in admin controller.

Instead extend from \Magento\Backend\App\Action class, so it will redirect you to login page instead of throwing an error.

  • Thanks, this was the solution. It is also staying logged in for a longer time. I didn't got logged out since the fix (yet).
    – Akif
    Aug 10, 2016 at 14:25
  • Btw, how did you know this was the problem. In other words, how did I had to solve this on my own? Did I mis a clue?
    – Akif
    Aug 10, 2016 at 19:13
  • in M2, there is different class for backend , where magento check session. You can also use \Magento\Framework\App\Action\Action but here magento doesn't validate session. Aug 11, 2016 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.