I use this code, on .phtml
file,
if($customerSession->isLoggedIn()) {}
for check if the user is logged. But, when I active the cache, this code does not work fine. How I can resolve this problem?
Utilising knockout is another approach
<div class="greet welcome" data-bind="scope: 'customer'">
<!-- 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)">
</span>
<!-- /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'))) ?>"'>
</span>
<!-- /ko -->
</div>
block
for phtml file from .xml file?