Show Element, When A Particular User Is Logged In

Hi, everybody
Good Day !
I am a bit confused in the code of my Wix website.


In my site, I have a dataset , a repeater - in the repeater a text, image and a button. But I want the button to show only if a particular user is logged in.
For Example - Ajith is logged in to my website. I want to make him see the button on a paricualar container of a repeater.
For more info -


Here is an input in my website, When the user types anything, I want to get which member uploaded it.

Then in the repeater, I want to show the ‘Delete Post’ button only to the user who uploaded it.

Hope you understand,
Ajith

Hello Ajit,

to show if a user is logged in, you can do it like this…

import wixUsers from 'wix-users';

$w.onReady(function () {
 let user = wixUsers.currentUser;
 let isLoggedIn = user.loggedIn;

 if(!isLoggedIn){console.log("User not logged-in.");}
 else {console.log("User logged-in");}
})

To achieve your aim, you have to do the following steps…

  1. Create a DATABASE or an ARRAY which will contain all the permissions of each user.
  2. Get the current loged-in user’s ID or e-mail to identify who is currently logged in and look into your DATABASE for PERMISSIONS for this user.

Take also a look at this example here…

https://russian-dima.wixsite.com/meinewebsite/comments

Hai Russian-dima,
Thank You for your help,

What I am trying to do is to show to button (in the repeater) to only those who upload the data in database.
For others , the button should not be there

Ajith

Ok, i think now i understand what you want to know.

Well, your mission will be …

  1. Find out how to get your button in the repeater.

https://www.wix.com/corvid/reference/$w/repeater/foreachitem

$w.onReady(function () {
2  $w("#myDataset").onReady( () => {
3    $w("#myRepeater").forEachItem( ($item, itemData, index) => {
4      if(itemData.button){
5        $item("#myText").text = "Yes Ma'am!";
6      }
7      else {
8        $item("#myText").text = "No way!";
9      }
10    } );
11  } );
12} );
  1. Find out the current user-id of logged in user.
import wixUsers from 'wix-users';

let user = wixUsers.currentUser;
let userId = user.id;
console.log(userId)
  1. Then make a little if-querry to check if the user has the permission or not in your database.

This video here could also be very interesting for you.

Thank You Russian-Dima,

Is there any feature, that would change the size of repeater, if there is no button to one user ?

Once More Thanks,
Ajith

You can try to collapse the elements which are not needed (untested).

Ok, I will make the ‘untested’ into ‘tested’
Thanks,
Ajith