SOLVED: Get any data from wixUsers

Currently, you can only get email and userID from wixUsers, but it would be nice if you can also get the photo, firstName, lastName and maybe even username! Would be so nice if that were possible.

9 Likes

I actually found a solution to this problem, but it’d be nice to have this feature built-in.

The solution

You can use wixData.query to get data from the dataset Members/PrivateMembersData . This is my script, divided in parts:

Put this all the way at the top of your code:

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

Put this underneath an event handler:

wixData.query("Members/PrivateMembersData")
            .eq("_id", wixUsers.currentUser.id)
            .find()
            .then((results) => {
               //script here
            })

Change //script here with this code snippet to display the username in a text element:
(I am using a text element with the ID #usernameText1 in this case)

$w('#usernameText1').text = results.items[0].username;

You can fetch any of the data by entering results.items[0]. and then one of these:

loginEmail
_id
name
firstName
lastName
picture
nicknames
slug
language
status
_createdDate
_updatedDate
lastLogin
emails
mainPhone
phones
4 Likes

Man, that is REALLY useful!
I wish I would have seen this post before.
Thanks a lot! Works like a charm :slight_smile:

1 Like

@eriksonsousa :slightly_smiling_face: You’re very welcome!

2 Likes

Hi, your answer seems really useful. I get an error though with the ‘#usernameText1’. Should I be changing this to something else? many thanks

1 Like

Your element’s ID should either be set to “usernameText1”, or you should change the “#usernameText1” in my code to your element’s ID.
The element I’m talking about must be a text element, in order to show the username correctly.

@webmasterq Hey! I’m trying to use your example or code but what I need is to extract the ID of the logged user and then pass the personal data (or insert( )) to a different database that corresponds to a form

1 Like

@andresberegovich Unfortunately, I think you could better post a new forum thread, since I am not really advanced with inserting to databases.

@webmasterq No worries! I already found a solution :slight_smile:

1 Like

Ok

When I use your code, using “username”, it works. But, when I try to get “_createdDate”, it doesn’t…? Any suggestion for fix?

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
wixData.query(“Members/PrivateMembersData”)
.eq(“_id”, wixUsers.currentUser.id)
.find()
.then((results) => {
$w(‘#textDate’).text = results.items[0]._createdDate;
})

@michaelallgier I believe that’s because all the fields with a _ are visible to admin only. There is a bug at the moment though that makes the whole database admin only, so my whole site is kind of broken lol :upside_down_face: