Direct answer to your question :
You dont, you should not check in phtml file.
customerSession is not available in block and this is normal, you can see which methods are available in here : https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/Block/Onepage.php
Important Advice: do not include any logic in templates, it is a very bad practice
Proper solution :
for that purpose you can use a plugin to change the result of redirection to cart to force login page :
etc/frontend/di.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Controller\Index\Index">
<plugin name="redirect_to_login_sso_instead_of_cart"
type="Project\Sso\Plugin\Frontend\Checkout\Controller\Index\IndexPlugin" sortOrder="10"
disabled="false"/>
</type>
</config>
and then in Project\Sso\Plugin\Frontend\Checkout\Controller\Index\IndexPlugin :
<?php
declare(strict_types=1);
namespace Project\Sso\Plugin\Frontend\Checkout\Controller\Index;
use Magento\Checkout\Controller\Index\Index;
use Magento\Customer\Model\Session;
use Magento\Framework\Exception\SessionException;
class IndexPlugin
{
/** @var Session */
private $customerSession;
public function __construct(
Session $customerSession
) {
$this->customerSession = $customerSession;
}
/**
* @throws SessionException
*/
public function afterExecute(
Index $subject,
$result
) {
if (!$this->customerSession->isLoggedIn()) {
$this->customerSession->authenticate();
}
return $result;
}
}
Tested 100% works.