Database query help

Hi I am looking to be able to give access to certain pages to members who have been given admin permission in the members database however when I use the getcurrentitem query it only works if the last person who signed up has been given admin permission and not the current user.
Here is the code I have been trying to use ;

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

$w.onReady( () => {

if(wixUsers.currentUser.loggedIn) {
$w(“#Login”).hide ();
$w(“#profileButton”).show();
$w(“#Logout”).show();
$w(“#myProfile”).show();

}
else {
$w(“#Login”).show();
$w(“#profileButton”).hide();
$w(“#Logout”).hide();
$w(“#myProfile”).hide();
}
});

export function Logout() {

// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixLocation.to(‘/home’);
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#Login”).show ();
$w(“#profileButton”).hide();
$w(“#Logout”).hide();
$w(“#myProfile”).hide();
});
}

}

export function Login() {

let userId; 
let userEmail; 

wixUsers.promptLogin( {“mode”: “login”} )
.then( (user) => {
userId = user.id;
return user.getEmail();

  } ) 
  .then( (email) => { 
    // check if there is an item for the user in the collection 
    userEmail = email; 
    return wixData.query("Members") 
      .eq("_id", userId) 
      .find(); 
  } ) 
  .then( (results) => { 
    // if an item for the user is not found 
    if (results.items.length === 0) { 
   // create an item 
      const toInsert = { 
        "_id": userId, 
        "email": userEmail 
      }; 
      { 
      // add the item to the collection 
   wixData.insert("Members", toInsert); 

}
(wixLocation.to(/Members/Update/${wixUsers.currentUser.id}));
}
//navigate to profile page
else { wixLocation.to(/${wixUsers.currentUser.id});
}
// update buttons accordingly
$w(“#Login”).hide();
$w(“#profileButton”).show();
$w(“#Logout”).show();
$w(“#myProfile”).show();

let admin = $w("#dataset13").getCurrentItem().admin; 

if (wixUsers.currentUser.loggedIn && admin === true) {
$w(“#fixtureUpdate”).show();
$w(“#upload”).show();
$w(“#membersB”).show();
}
else {if (wixUsers.currentUser.loggedIn && admin === false)
$w(“#fixtureUpdate”).hide();
$w(“#upload”).hide();
$w(“#membersB”).hide();
}

});
}

export function myProfile_click() {
wixLocation.to(/Members/${wixUsers.currentUser.id});
}

export function profileButton_click() {
wixLocation.to(/Members/${wixUsers.currentUser.id});
}

everything else works great except the check admin permission any help would be very much appreciated. Thanks

Hi Keith!

Please provide us with a link to your site so one of Wix workers can inspect it and look for a solution to your issue.

Thanks!

Doron. :slight_smile:

Hi Doron the site is www.eastdurhamlions.com thanks