Hide() and show() not working on my pages

Question:
i have pages that have text which shows up when a user is logged in, and then the same text is hidden when they are logged out. I have been using this code to run this for the past 4-5 months without any issues. But yesterday the code just seemed to stop working now I can’t get the hidden text to appear when the users try to log into my website. Does anyone know if there has been an update or if I made a mistake in the code?

Here is the code below & the affected element tags I commented saying “not showing”:

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady(() => {

const user = wixUsers.currentUser;
const userId = user.id;
const loggedIn = user.loggedIn;

if (wixUsers.currentUser.loggedIn) {
        $w('#text138').show(); //not showing
        $w('#text139').hide();

} else {
        $w('#text139').show();
        $w('#text138').hide();

}

});

Product:
I am working on Wix Studio

What are you trying to achieve:
I want the hidden text to appear when a user is logged in.

What have you already tried:
I’ve tried just renaming the elements in the code and also looked for other people with similar issues but couldn’t find anyone

Additional information:
I’ve attached images of what the page should look like and also what’s currently happening and what the code panel shows when i preview the page. This issue is going on throughout my site. the code i posted is from another page but the images I attached basically shows the issue as a whole.

code panel in preview

Current homepage (broken)

What home page should look like

Thanks for any help!

Can you add a console message and check your browser’s developer console on the live site to see if the condition is being reached?

This should help you debug whether it is a issue with Wix Users.

Example


if (wixUsers.currentUser.loggedIn) {
        console.log('User is logged in'); // New Line
        $w('#text138').show(); 
        $w('#text139').hide();

} else {
        console.log('User is not logged in'); //New Line
        $w('#text139').show();
        $w('#text138').hide();
}

I also recommend potentially updating to loggedIn() from our new Wix Members Frontend API

Example

import { authentication } from "wix-members-frontend";

$w.onReady(async function () {

    const isLoggedIn = authentication.loggedIn();

    if (isLoggedIn) {
        console.log("Member is logged in");
    } else {
        console.log("Member is not logged in");
    }

});
1 Like