Stripshow for logged in owner or everyone

Hi there, any ideas for coding the start of this. I have two strips one which i would like to show the logged-in owner who is viewing a dynamic page and the second strip should only be shown to a non-logged in user who is viewing the dynamic page without being a member.

I’m thinking something along the lines of

get current user - is logged in owner
show strip 1
hide strip 2
else - not logged in or a member
show strip 2
hide strip 1

or something like this
Thanks
Adam

Yes.

import wixUsers from 'wix-users';
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
$w.onReady(() => {
    if (isLoggedIn){
        doIfLoggedIn();
} else {
        $w("#strip2").expand();
        $w("#strip1").collapse();
}
})
wixUsers.onLogin( (user) => {
  let userId = user.id;      
  let isLoggedIn = user.loggedIn;
  doIfLoggedIn();
 
} );
function doIfLoggedIn(){
 $w("#strip1").expand();
$w("#strip2").collapse(); 
}

great thanks, i have imported Wix users at the top of the code page, just want to check this error in red please as showing parsing error unexpected token

let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;

if (isLoggedIn){
doIfLoggedIn();
} else {
$w(“#columnStrip12”).expand();
$w(“#columnStrip13”).collapse();
}
})
wixUsers.onLogin( (user) => {
let userId = user.id;
let isLoggedIn = user.loggedIn;
doIfLoggedIn();

} );
function doIfLoggedIn(){
$w(“#columnStrip12”).expand();
$w(“#columnStrip13”).collapse();
}

Thanks
Adam

@adcatch02 you’re missing the

$w.onReady(() => {

at the beginning (see my code above).

sorry yes, its because i thought i already had one as follows from a previous addition of code
import wixUsers from ‘wix-users’;
$w.onReady(() => {
$w(“#dynamicDataset”).onReady(() => {

sorted it thanks

Somehow managed to lose the functionality here. I have reviewed your the posts and replaced like for like as follows but not sure why this isn’t working now.
There are a couple of issues that might be connected, like the fact that I cannot get a string to pick up the field key either

I thought it might have been to do with user permissions?

$w.onReady(() => {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
$w.onReady(() => {
if (isLoggedIn){
doIfLoggedIn();
} else {
$w(“#columnStrip13”).expand();
$w(“#columnStrip12”).collapse();
}
})
wixUsers.onLogin( (user) => {
let userId = user.id;
let isLoggedIn = user.loggedIn;
doIfLoggedIn();
} );
function doIfLoggedIn(){
$w(“#columnStrip12”).expand();
$w(“#columnStrip13”).collapse();
}

  1. Remove the first line. (the extra onReady)
  2. Don’t forget to import wixUsers

Then I get a warning to say user is already declared in upper scope

  1. do it.
  2. inside the wixUsers.onLogin remove the “let” words.

let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
$w.onReady(() => {
if (isLoggedIn){
doIfLoggedIn();
} else {
$w(“#columnStrip13”).expand();
$w(“#columnStrip12”).collapse();
}
})
wixUsers.onLogin( (user) => {
$w.onReady(() => {
let userId = user.id;
let isLoggedIn = user.loggedIn;
doIfLoggedIn();
} );
function doIfLoggedIn(){
$w(“#columnStrip12”).expand();
$w(“#columnStrip13”).collapse();
}

import wixusers is at the top of my page

get rid of your second $w.onReady(() (the one that is inside the onLogin)
and as I said, remove the “let” words from there

See my comment above.
Do it like this:

wixUsers.onLogin(u => {
    userId = u.id;
    isLoggedIn = u.loggedIn;
    doIfLoggedIn();
})

which lets the top or bottom, i though onReady was in the right place?

You did the opposite. Don’t remove the “let” from the beginning. Move it from the onLogin.
You know that once you declare a variable in the global scope, you can’t declare it again.

ok done as per previous first image, so now what am i missing?

J.D. this was working so not sure if this has anything to do with the dynamic page being re-titled ? I don’t remember changing any of this code although i must have done something to it

J.D. this code was working so i’ve gone back to the original snippet but still have a parsing error

This did work i’m sure it did? other than the parsing error