Help filtering dataset by email (not owner)

So I have jumped around multiple posts to understand how get my data set to filter properly.
I have values that would be manually created and updated by the admins. And I need to set it up, so the users can access what belongs to them without being able manipulating it or see ones that don’t belong to them.

I got a mess of code here as I can’t get the filter to work with variables. If some can please help me understand what to do.

Here is my code:

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

$w.onReady(() => {
$w(“#dataset1”).onReady(() => {
let email = wixUsers.currentUser.getEmail()
.then((emailget) => {
let userEmail = email; // “user@something.com
$w(“#dataset1”).setFilter(wixData.filter().eq(“email”, email));
$w(“#dataset1”).setSort(wixData.sort().ascending(“pubdate”));
});

}); 

});

While I can get the information to show up on the table, I can’t get it to filter it properly.
I also can’t tell if I am actually getting the current login user’s email.

Hello! Did you manage to solve it?

Should look something like this… (it’s not totaly 100% complete) but you will be able to modify it to get it to work :wink:

import wixUsers from 'wix-users';
import wixData from 'wix-data';

const DATABASE  = "Your_DB_ID_here";          //---> Collection(ID)
const DATAFIELD = "Your_DATAFIELD_ID_here";   //---> DB-FIELD (Column-ID)
const VALUE = "Your_SEARCH_VALUE_here";       //---> E-Mail

$w.onReady(async()=>{
   await getUserData();
   $w('#myButton').onClick(()=>{checkDB4EmailData();});  
});

function checkDB4EmailData(eMail) {
   wixData.query(DATABASE)
   .eq(DATAFIELD, VALUE)
   .find()
   .then((results)=>{
      if(results.items>0) {
         let items = results.items; console.log(items);
         if (items[0].DATAFIELD) {console.log(items[0].DATAFIELD);
          //continue your CODE here .....
      }
      else {console.log("No DATA found!")}
   });
}

function getUserData() {
   let user = wixUsers.currentUser;    console.log(user)
   let userID = user.id;               console.log("User-ID: ", userID)  
   let isLoggedIn = user.loggedIn; 

   user.getEmail()
  .then( (email) => {
     let userEmail = email;
  });
}

Ohh, forgot to tell you, that this VERSION do not need a DATASET :roll_eyes: