API WIX USER TO WIX MEMBER

Hello everybody,
i normally used the function below to get the user email in the code but recently an error appear during the test mode(e.text is not a function).
T


he wix support team told me that the API WIX USER is deprecated and i have to get the user email by using the Get email function in the API WIX MEMBER.
Can anybody help me to change my code in the updated version? thank you very much
$w . onReady ( function () {
let user = wixUsers . currentUser ;
let userid = user . id ;

user . getEmail () 

. then ( ( email ) => {
let useremail = email ;

wixData . query ( "GymTraining" ) 
      . eq ( "_id" ,  userid ) 
      . find () 
      . then (( results ) => { 
           if  ( results . items . length  ===  0 ) { 
      $w ( "#button1" ). show (); 

      
      
    } 

else {
$w ( “#button1” ). hide ();
}

});
} );

});

I am always telling → NOT TO USE → DEPRICATED API-STUFF :grin:
Here we have a case → which confirms my words :grin:

Well about Wix-Members-API, you already took a look onto it?
https://www.wix.com/velo/reference/wix-members/introduction

I get help to made this function since the corvid years.
Yes i had a look in wix-memberr-api and seems that i have to use getemail function but i have some difficulty to build the code.
With that function i should get the email of the logged in user and if is not present in the dataset the button have to be shown.
Be patient but i am not an expert in coding, i am still learnig😊

So, the functionality you want to generate is to determine who is the current logged-in-user on your site, after a user has logged-in onto your site.

Should be something like this one…(this is the FRONT-END-VERSION).

import { currentMember } from 'wix-members';
    
$w.onReady(async()=>{console.log("Page is ready...");
    let options = {fieldsets: [ 'FULL' ]}
    let currentMemberData = await currentMember.getMember(options)
    const id = currentMemberData._id;
    const firstName = currentMamberData.contactDetails.firstName;
    const lastName = currentMamberData.contactDetails.lastName;
    const fullName = `${firstName} ${lastName}`;
    //-------------------------------------------------
    console.log("Member-Data: ", currentMemberData);
    console.log("Member-ID: ", id);
    console.log("Member-Firstname: ", firstName);
    console.log("Member-Lastname: ", lastName);
    console.log("Member-Fullname: ", fullName);
});

Not excactly….i would like to
keep the logged in email
Query my dataset if his email is inside my dataset
If its present hode a button
If its not present show a button

DATASET or DATABASE ? → DON’T MIX THEM UP !!!

In your code…

.
..
...
wixData.query("GymTraining")
.eq("_id", userid)
.find()
.then((results) => {
    if (results.items.length === 0) {
$w("#button1").show();
...
..
.

You are queriying a → DATABASE with the ID → “GymTraining” <—
There are no CODE-PARTS showing anything about a → DATASET !!!

Also you are not really using your e-mail, instead you are using the USER-ID , to get related results from your —> DATABASE.

Did you already run the CODE ?
Which RESULTS did you get?

Show a screenshot with opened Object.

Did i call it database?
No no it a dataset/collection
The final idea is that
If the logged in user is present in the dataset the button is hided.
If the logged in user is not present in the dataset the button is shown
the onclick function of this button will create a new item in the dataset( with the email)

I think you mix it up.

What is a database?
A database is = Collection and Collection is = database.
You store all your items inside your database in different database-fields (rows and columns) like on an microsoft’s excel-sheet.

What is a -->DATASET<-- ???
A dataset is some kind of a connection (wire) between the databse and a displaying element, like —> REPEATER, TABLE, GALLERY, HTML-COMPONENT, TEXT-BOX and so on…

In your code you don’t have any codeline, which is related to a dataset.

  1. Copy and paste my provided code onto your page.
  2. Publish your website.
  3. Run the code, by logging in onto your website and opening the related page, where you placed the code.
  4. Press F12 on your keyboard, while you are in your Webbrowser (google-chrome).
  5. Navigate to —> CONSOLE !
  6. Take a look onto the given results → you will understand the rest.

Ok i understood how to call them correctly.
This evening i will try the code.
Thanks for the moment i eill let you know

YEAHHHHH
Seems working and the error is disappear…I just made these corrections and added the function to insert an Item if the user is not present in the Collection.
can you please tell me if i made good?

If it works = you made good!:wink: