Get current-user's First Name

Hi (:
I would like to know how I can access the First and Last names of the current user.
By code, of course.

Thank you very much!

1 Like

Hi Uriel!

Accessing data about the user is tricky.
The data that is available without user input is limited to the following:
Email , id (a unique string), role (is the logged-in user is a member? an admin?) and a last indicator field of rather the current user is even logged in or not?

Other than that, you’ll need to ask your user to fill in any additional info. that you’d like to use in the future (that goes for first name, last name, phone number, date of birth, etc. etc…)

You can look into the Wix-Users API to learn more about your capabilities on this matter.

Hope it helps!

Doron.

I have collected the above information from the user.
I have all the information stored in the members and contacts of the site. My only question is how to access it using code.

Hi Uriel!

Simply use a WixDataQuery to retrieve the data from your collection.
Assign the respond into variables and Voila! - you can use / access / alter and what not.

Check the API documentation for examples and guidance.

Doron.

Only problem is that I don’t know what’s the collection name of the contacts/members of the site. Could you help me with that please?

You can access the members data with this collection name: “Members/PrivateMembersData”. see Wix Members “PrivateMembersData” Collection Fields

It is already mentioned in the Wix Users API and with a fully coded example too.
https://www.wix.com/corvid/reference/wix-users.html

How can I get the current user’s name?
Use the currentUser property to get the current user’s id. Then query the Members/PrivateMembersData collection for the item with that _id.

wixData.query("Members/PrivateMembersData")
  .eq("_id", wixUsers.currentUser.id)
  .find()
  .then( (results) => {
    lastName = results.items[0].lastName;
  } );

This post is from 2018 and being closed.