Can't get email for logged in member

What is wrong with my code? Current user is ok and i can see it’s role, but email is empty…why?

import wixUsers from ‘wix-users’;
var userEmail=“”;

$w.onReady( function (){

const currentUser = wixUsers.currentUser;
if (currentUser.loggedIn)
{
currentUser.getEmail()
.then( (email) => {
userEmail = email;
} );
}

See the api here:
https://www.wix.com/code/reference/wix-users.User.html#getEmail

user.getEmail()
  .then( (email) => {
    let userEmail = email; // "user@something.com"
  } );

Something like this:

 import wixUsers from 'wix-users';  
 
 $w.onReady(() =>{
 
 let user = wixUsers.currentUser; 
 let email = user.getEmail()
  .then((email) => {
   let userEmail = email;
  });

Or like this:

import wixUsers from 'wix-users';

let user = wixUsers.currentUser;
console.log(user);
var email;
$w.onReady(async function () {
    email = await user.getEmail();
});

isn’t that exactly the code i wrote?

Same problem happens to me.
I wrote the same code but the userEmail is undefined while the user is logged in.

Please help.