Filtering Dataset Against a Variable

Hi everyone,
I know this is an easy one but I do not know why does not it work.
I am trying to filter a dataset based on the user login email. so I store the login email in a variable and use this variable to filter the dataset.
However, it is not working. when I try to hard code the login email it works fine.
the code is as below.

appreciate your support.


import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;

let user = wixUsers.currentUser;
let userEmail = “test”

export function dataset1_ready() {
user.getEmail()
.then((email) => {
userEmail = email;
$w(“#text46”).text = userEmail;
});

$w("#dataset1").setFilter(wixData.filter() 
    .eq("title", userEmail) 
); 

}

You have to put the setFilter inside the “then” block. Otherwise it’ll run the filter before the getEmail() promise has been resolved.

Thank you very much