getCurrentMember result

I’m working on WIX Editor with WIX velo

Dear Wix code experts, here is my issue :

I create a site for free exchanges of games

I have created a collection for the games, one field is the email of the owner of each game

I have created a page to display all the games of the current member, my purpose is to filter on the email field. I have to retrieve the mail of the current member.

I am not expert in javascript and velo wix, although I have used it already for a few things.

So I’m trying with

import { members } from “wix-members.v2”;

and

const member = members.getCurrentMember() ;

But after that, I don’t know what to do just to retrieve the mail address of the current member.

Thanks so much for helping me if possible.

Isabelle (sorry for my desperately approximate English)

A. For readability, please format your code like so:

For inline code use `code`
For multi-line code, use:
```js

yourCode() { 
    here
}

```

B. wix-members.v2 is still in beta, so I recommend using wix-members-frontend

import { currentMember } from "wix-members-frontend"
// asynchronous function, gotta wait for it to return the results
currentMember.getMember().then(member => {

})

C. You have set a constant member, and want to check what it contains, you can access its properties using member.propertyName or member['propertyName']

You can see the various properties returned by looking at the documentation for the method you’re executing:

You can also see it in real time by logging it to the console:

console.log(member)

You’ll get a JSON with the data of member

Thank you very much, DeanAyalon, I think I’m on progress !

I am able now to display the loginEmail of the currentUser
either in the masterPage.js:

import { currentMember } from "wix-members-frontend";

currentMember
  .getMember()
  .then((member) => {
    const id = member._id;
    const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
    const mailOwner = member.loginEmail;
    console.log(id);
    console.log(mailOwner);
    return member;
  })
  .catch((error) => {
    console.error(error);
  }
  
  );

or in the member page:

import { currentMember } from "wix-members-frontend";

$w.onReady(function () {

currentMember
  .getMember()
  .then((member) => {
    const id = member._id;
    const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
    const mailOwner = member.loginEmail;
    console.log(id);
    console.log(mailOwner);
    return member;
  })
  .catch((error) => {
    console.error(error);
  }
  
  );
});

But there is still a problem:

console.log(mailOwner);

doesn’t work when it is outside the member §.

So I can’t use it to filter my dataset.

Or can I? how?

I’m very grateful that my issue catches your attention.

I have a tutorial for that …

1 Like

Thank you for your tutorial, it helps me very much!

"The Good to Know [#2] " § gives me a solution, perfect!

I still wonder why “The Good to Know [#1]” § doesn’t work:

In this case, the field “owner” has been created after the dataset initialization.

When I create my dataset, the system field “Proprietaire” (that’s to say “Owner”) has been created, but it doesn’t contains the email, it contains a code, not usable.

How can I have this precious field which makes automatically appear “Logged-in user” in the filter?

The Owner ID that gets created is usable for coding purposes.

If you created your own “Owner” field, that will do nothing in the code.

OK, so is that Owner Id a “system” field?
How can I do to create a collection with such a field?
Sorry for my inexperience

Every item automatically gets an “owner” field. The “owner” is the person that is logged in that entered the item into the database. So if YOU are the one entering all the data into the database, then YOU are the owner of that data. You are the “Author” basically.

You cannot assign it to anyone else.

If you want the Member to be the owner of the field, then they need to be logged in and they need to insert the data into the database themselves.

1 Like

OK, I have all the informations to get further. Thanks a lot!