Get the Logged-In User with $app->getIdentity() (Replaces JFactory::getUser)
Reads ID, name, email, groups and guest status of the active user using the native Joomla 5 and 6 Identity API.
<?php
declare(strict_types=1);
use Joomla\CMS\Factory;
$user = Factory::getApplication()->getIdentity();
// ...