Can't Get Wix User ID and Email

Once a user registers or logs into my page, I am looking to copy the user id and email into my Associate table. But for some reason, there is no value when I call wixUsers.currentUser.id or wixUsers.currentUser.getEmail(). However, when I hard-code values (as shown commented out below) it works 100% of the time. I must be doing something wrong. This code is at the site level, not the page level. Thanks!

import wixUsers from 'wix-users';
import wixData from 'wix-data';

$w.onReady(() => {
	add();
});

export function add() {
	let userId = wixUsers.currentUser.id;
	let userEmail = wixUsers.currentUser.getEmail();
	
	//let userId = "test123";
	//let userEmail = "test@test.com";
	
	return wixData.query("Associate")
		.eq("_id", userId)
		.find()
		.then((results) => {
			// if an item for the user is not found
			if (results.items.length === 0) {
				// create an item
				const toInsert = {
					"_id": userId,
					"email": userEmail
				};
				// add the item to the collection
				wixData.insert("Associate", toInsert)
					.catch((err) => {
						console.log(err);
					});
			}
			});
}

Here is another code snippet. I am getting the User ID, just not the email. The user registers through the Wix login screen by both email and Facebook. I am then outputting the USER ID and EMAIL to the screen.

import wixUsers from 'wix-users';

$w.onReady(function () {

	let user = wixUsers.currentUser;
	let userEmail;

	user.getEmail()
		.then((email) => {
			userEmail = email;
		});

	$w("#text19").text = user.id;
	$w("#text20").text = userEmail;

});

Due to the fact that user.getEmail is resolved with a Promise (with then()) the line of code assigning the userEmail to text20 runs before you get the email. Move $w(" #text20 ").text = userEmail; to the place you get the email and assign it.

Thanks Shay. I have a lot to learn!

@lperroots did you ever get a working code for this?