If you want to add to the different class to the body when the customer is logged out and logged in.
Create a custom module, which will add two custom layout handles, for example, customer_logged_out
and customer_logged_in
and add those handles to the layout.
Use the following code as the sample and modify it according to your requirement.
app/code/Anshu/Custom/Observer/AddHandles.php
<?php
namespace Anshu\Custom\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Customer\Model\Session as CustomerSession;
class AddHandles implements ObserverInterface
{
protected $_customerSession;
public function __construct(CustomerSession $_customerSession)
{
$this->_customerSession = $_customerSession;
}
public function execute(Observer $observer)
{
$layout = $observer->getEvent()->getLayout();
//To check that customer is logout
if (!$this->_customerSession->isLoggedIn())
{
$layout->getUpdate()->addHandle('customer_logged_out');
}
}
}
app/code/Anshu/Custom/view/frontend/layout/customer_logged_out.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<attribute name="class" value="my-class-test"/>
</body>
</page>
Above code is for the logged out customer, similarly, you can do it for logged in the customer as well.