Get currently logged in user
Try this

&lt;?php
// Load the current user.
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id());

// get field data from that user
$website = $user-&gt;get('field_website')-&gt;value;
$body = $user-&gt;get('body')-&gt;value;


$email = $user-&gt;get('mail')-&gt;value;
$name = $user-&gt;get('name')-&gt;value;
$uid= $user-&gt;get('uid')-&gt;value;
?&gt;


Or

$uid = \Drupal::currentUser()-&gt;id();
$user = \Drupal\user\Entity\User::load($uid);
$name = $user-&gt;getUsername();


You will get more details about User::getUsername.