Zend certified PHP/Magento developer

Get customer_logged_in value from http_context

I’m trying to check if the user is logged in. But the problem is in my code eventhough I already logged out it’s still check and output that the user is still logged in. Below is my code

< ?php
namespace TcmGoodgiftsHelper;

class Customer extends MagentoFrameworkAppHelperAbstractHelper
{
    public function __construct(
        MagentoFrameworkAppHelperContext $context,
        MagentoCustomerModelSession $customerSession,
        MagentoFrameworkAppHttpContext $httpContext
    ) {
        $this->customerSession = $customerSession;
        $this->context = $httpContext;
        parent::__construct($context);
    }

    public function isLoggedIn()
    {
        var_dump($this->context->getValue(MagentoCustomerModelContext::CONTEXT_AUTH));

        var_dump($this->customerSession);

        return $this->customerSession->isLoggedIn();
    }
}

So basically if I run the bin/magento setup:upgrade the correct output is being displayed. But after I log out or login it retains the old state and not the new one. When I outputted the value of $this->context->getValue(MagentoCustomerModelContext::CONTEXT_AUTH) it give me this

enter image description here
enter image description here

So as you can see it somehow get the value under _httpContext->data["customer_logged_in"] but when checking the value I think the correct value should be the one under the _httpContext->default["customer_logged_in"] but I don’t know how to get this value.

Just by running $this->context->getValue(MagentoCustomerModelContext::CONTEXT_AUTH) will retrieve the object Data and not the Default.

Any idea how to get this value? I’m guessing the Default note returns the correct/updated value