Hi team, I hope you are all doing great.
I have attached this code to my Dev Tool>
import wixUsers from ‘wix-users’ ;
$w . onReady ( () => {
if ( wixUsers . currentUser . loggedIn ) {
$w ( ‘#loginbutton2’ ). hide ();
}
else {
$w ( ‘#loginbutton2’ ). show ();
}
});
but, once I logged in the site kept showing me the button, if I reload the page then the button hides but it is supposed to hide as soon as I log in right?
Thanks for your help
Hi @icariacr ! The code you have provided is designed to hide a specific button with an ID of “loginbutton2” when the user is logged in. It should work as expected and hide the button as soon as the user logs in. However, it’s possible that there could be a delay in the code execution. One thing you could try is to wrap the code inside the wixUsers.currentUser.onChange() function, which will be triggered whenever the user’s authentication status changes. Good luck!
There are few things which are not correct!
It should work as expected and hide the button as soon as the user logs in
Not completely correct!
This code only checks for logged-in user when the PAGE-IS-READY !!!
And yes, this is exactly what happening!
If you are already on the page and then do the logging, the page is already READY, and it won’t check for logged-in-user anymore → RESULT → you have to refresh the page to get the page onReady agian.
So at least at this point you are missing the following…
https://www.wix.com/velo/reference/wix-users/onlogin
But the second and more important information for you would be NOT TO USE THE OLD AND DEPRICATED → USERS-API ANYMORE !
Instead use the new MEMBER-API in the future, if you don’t want to get problems with your User-Identification in the future and start to recode all your code again.
https://www.wix.com/velo/reference/wix-members/authentication
Hello! I’m also noticing you are using wix-users. This is deprecated and while it will still continue to work, if you are starting a new project you will want to move forward with wix-members
haha! I just saw your comment about using wix-members after I posted the same thing! Thank you for adding this advice to your comment
We have very often similar thoughts 