Hi,
I have a function that’s supposed to display the user’s nickname.
I call this function in two occasions:
- On page load (if the user is already logged in).
- When the user logs in. - onLogin()
Now, it works well when the page loads, but not when the user logs in.
Here’s my code. What am i doing wrong?
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
function getNickname() {
wixUsers.currentUser.getEmail()
.then((email) => {
wixData.query("Members/PrivateMembersData")
.eq("loginEmail", email)
.find()
.then( (results) => {
$w("#text63").text = results.items[0].nickname;
} )
})
.catch( (err) => {
let errorMsg = err;
} );
}
getNickname();
wixUsers.onLogin( () => {
console.log("User Status: " + wixUsers.currentUser.loggedIn);//it logs: "User Status: true"
getNickname()
})
})
Thanks,
J.D.