Hi,
I used this code,
wixUsers.onLogin( () => {
$w('#UserOnly').hide();
} );
but sometimes even when the user is logged in, the box still shows.
So then the user need to log out and then log in again.
Any idea what to do?
Thanks,
Jakub
Hi,
I used this code,
wixUsers.onLogin( () => {
$w('#UserOnly').hide();
} );
but sometimes even when the user is logged in, the box still shows.
So then the user need to log out and then log in again.
Any idea what to do?
Thanks,
Jakub
Hi Jakub,
The onLogin event fires only once a login is performed by a site visitor.
If you wish to hide a box for logged in users you should also check if the user is logged in once the page loads and hide the element if it equals to true:
import wixUsers from 'wix-users';
$w.onReady(function () {
hideElem();
});
wixUsers.onLogin(() => {
hideElem();
});
function hideElem() {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
if (isLoggedIn) {
$w('#UserOnly').hide();
}
}
Good to know. Thank you Ido.
exactly what I was looking for. worked just fine for me. thanks