Now I implement the code below

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Http\Context as AuthContext;

class Customer extends AbstractHelper
     * @var \Magento\Framework\App\Http\Context
    private $httpContext;
    private $objectmanager;
    private $authContext;

    public function __construct(
        \Magento\Framework\App\Helper\Context $context,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Framework\ObjectManagerInterface $objectmanager,
        Session $session,
        AuthContext $authContext
    ) {
        $this->objectmanager = $objectmanager;
        $this->httpContext = $httpContext;
        $this->customerSession = $session;
        $this->authContext = $authContext;


    public function isLoggedIn()
        $isLoggedIn = $this->authContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);

        return $isLoggedIn;   

But when I refresh my page it still say that it's login eventhough I already logged out. Below is the code of my template

    $customerHelper = $this->helper('Vendor\Module\Helpers\Customer');

<ul class="menu_list">
<?php if ($customerHelper->isLoggedIn()): ?>
        <a href="<?= $this->getUrl('customer/account'); ?>"><?= $block->escapeHtmlAttr(__('Account')) ?></a>
        <a href="<?= $this->getUrl('customer/account/logout'); ?>"><?= $block->escapeHtmlAttr(__('Logout')) ?></a>
<?php else: ?>
        <a href="<?= $this->getUrl('customer/account/login'); ?>"><?= $block->escapeHtmlAttr(__('Login')) ?></a>
<?php endif; ?>             

Update: - When I logout the account still thinks that I'm still login. When checking the function response it says that I'm still logged in. I'm not sure how to fix this. Upon checking the session when I'm logged out there are no values of firstname for the mage_cache_storage. But when I'm loggedin its being populated. I think a Javascript is populating this value that's why the PHP script still thinks I'm logged in.. I'm not sure how to fix this

1 Answer 1


Maybe try a different approach


    <!-- ko if: customer().is_logged_in  -->
    <span class="logged-in"
            data-bind="text: new String('<?= $block->escapeHtml(__('Welcome back %1', '%1')) ?>').replace('%1', customer().firstname)">
    <!-- /ko -->
    <!-- ko ifnot: customer().is_logged_in  -->
    <span class="not-logged-in"
            data-bind='html:"<?= $block->escapeHtml(__("Please <a href='%1'>login</a>", $block->getUrl('customer/account/login'))) ?>"'>
    <!-- /ko -->

Is_logged_in comes from the plugin


Dont forget data-bind="scope: 'customer'

  • Glad this helped Commented Feb 24, 2020 at 23:47

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.