How to get the uid of a newly created user?
Where are you creating the user? Could you use entityTypeManager and EntityStorage instead of User::create()? I have the following in a method in a custom entity:

$storage = $this-&gt;entityTypeManager()-&gt;getStorage('user');
$owner =  $storage-&gt;create(['mail' =&gt; $email, 'name' =&gt; $this-&gt;getName()]);
$owner-&gt;save();
$uid = $owner-&gt;id();


If you don't have access to entityTypeManager() in your class, you could alternatively use:

$storage = \Drupal::service('entity_type.manager')-&gt;getStorage('user');