Hello,
My website has a login function to provide users information’s related to their accounts only
On a specific page (which is member only), I need to pick up the email to filter data
Here is the code:
userEmail = wixUsers.currentUser.getEmail();
var res = String(userEmail);
My variable res is not the email but the value [Object Promise]
Any ideas about my mistake ?
Many thanks
Pierre-yves
Yes Pierre, the problem is that everything in Wix Code is async. So you have to WAIT for the PROMISE to be RESOLVED. A copy of the doc:
user.getEmail() .then( (email) => { let userEmail = email; // “user@something.com” } );
The THEN is the party trick here: anything belonging to the THEN will wait for a resolve. In your code, you do not wait.
Also, Yoav posted a new trick (parallel to the new Chrome release: the async/await syntax). Look for this here on the forum if you want to have your code function more like a sync (instead of async) language.