Guys. So I have this function that changes the label of a button to Log in or Logout depending on whether member is logged in or logged out. It has been working perfectly until I noticed it no longer works. The button is supposed to open the sign in lightbox when member is not logged in and logs out if member is logged in. That part of it works well. But the label no longer changes, therefore making it really confusing. What could be causing this?
Hi, @user3306 !!
If that functionality is implemented using Velo code, sharing it might help someone in this forum assist you. Of course, please make sure not to include any private information in the code.
import { authentication } from “wix-members-frontend”
$w.onReady(function () {
authentication.onLogin(alterAuthButtonLabel);
authentication.onLogout(alterAuthButtonLabel);
})
function alterAuthButtonLabel() {
const loggedIn = authentication.loggedIn();
if (loggedIn) {
$w(“#loginButton”).label = “Log Out”;
} else {
$w(“#loginButton”).label = “Log In”;
}
}
Here it is. Fairly simple and it should work. No?
Hi, @user3306 !!
I checked the official reference. For now, how about making the code close to the one in the reference like this?
import { authentication } from "wix-members-frontend"
$w.onReady(function () {
alterAuthButtonLabel();
authentication.onLogin(() => {
alterAuthButtonLabel();
});
authentication.onLogout(() => {
alterAuthButtonLabel();
});
})
function alterAuthButtonLabel() {
const loggedIn = authentication.loggedIn();
if (loggedIn) {
$w("#loginButton").label = "Log Out";
} else {
$w("#loginButton").label = "Log In";
}
}
It actually works. Thank you very much, my friend