onLogin()

Hi,
I have a function that’s supposed to display the user’s nickname.
I call this function in two occasions:

  1. On page load (if the user is already logged in).
  2. 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.

Anything?

Did you manage to solve this?

It was an old question and I don’t really remember.
But I think that onLogin() doesn’t trigger if the page permissions are set to “members only” (at least that was an issue back then).
So you can try the following solutions:

  1. Remove the permissions limitation but write a code so to prompt login if the current user is not logged-in (and use the .then() part to run the code once the user got logged in).

  2. Leave the permissions restriction as they are but use a certain element on the page with onViewportEnter to trigger the function (the element is displayed only after the user has logged in due to the permission rules.