Get user first name

Hey,

I know how to get the email of the current login user.
(Im using this code >>

let user = wixUsers.currentUser;

user.getEmail()
.then( (email) => {
let userEmail = email;
$w(“#emailText”).value = userEmail;
} );

How do I do the same thing for his first name?
(How do I get the first name of the current user)

Thanks.

1 Like

@ Sivan Yitzhak

You can’t as wix-users is rather limited in what you can read from it.

What most people end up having to do is create a separate database where they store the names and read the names from there.

So what you end up with is having the names stored in WIX-CRM and also having the names stored in a separate database.

Thanks Mike

What I did is this:

if (isLoggedIn) {
    wixData.query("Members/PrivateMembersData")
        .eq("_id", wixUsers.currentUser.id)
        .find()
        .then((results) => {
           //This changes the text to for example Hi Sivan:
           $w("#yourText").text = "Hi " + results.items[0].firstName;
           //Put any script using the variable here
        })
}

With this code you can let a text box (yourText) say Hi Sivan (or the current user’s name). You can also change button labels, but then you have to change .text to .label.
Hope this helps!

You actually can, but in a different way.

if (isLoggedIn) {
    wixData.query("Members/PrivateMembersData")
        .eq("_id", wixUsers.currentUser.id)
        .find()
        .then((results) => {
           //This changes the text to for example Hi Sivan:
           $w("#yourText").text = "Hi " + results.items[0].firstName;
           //Put any script using the variable here
        })
}

Hi does this code still work bud? it only seems to work for me in preview mode, would this be something to do with the permissions of the Members/PrivateMemberData? to only allow admin to view it? thanks

The code suggested by Quinten has worked in the past (just 2 or 3 weeks ago), but as Stevo suggests, it isn’t working today. It now throws an error (error text below). I don’t know precisely when it began to fail. Can someone confirm whether this is an anomaly or if it’s the new “expected/correct” behavior?

This is the error I get (whether called as admin or non-admin user:
Error: {“message”:“missing_context, details: {"fields":"MSID / (appDefId, instanceId)","apps":"null","entities":"{\"context\":{\"appDefId\":\"eb377299-86b4-4a86-a1b5-774a2d1d374b\"},\"identities\":[{\"service\":{\"appDefId\":\"eb377299-86b4-4a86-a1b5-774a2d1d374b\"}}]}"}”,“details”:{“entities”:“{"context":{"appDefId":"eb377299-86b4-4a86-a1b5-774a2d1d374b"},"identities":[{"service":{"appDefId":"eb377299-86b4-4a86-a1b5-774a2d1d374b"}}]}”,“error”:“missing_context”,“fields”:“MSID / (appDefId, instanceId)”,“category”:“api_error”,“apps”:“null”}}

The Wix Members app collection called Members/PrivateMembersData should be readable only by the Site Member Author only. Which basically means that only that unique site member will be able to read their own data and nobody else will have the permissions to do so.
https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields

However, there is a current bug with it that has made the permissions for the collection change from Site Member Author to Admin instead.

If you search the forum for previous posts you should find a couple very recently about this issue.

It is currently being looked into and a fix will be sorted as soon as it is ready.

To workaround it at the current moment you can simply make use of the Wix Data Options.
https://www.wix.com/corvid/reference/wix-data.html#WixDataOptions

If you simply want to show the site members first name on their dynamic page for example, then just have a simple text box element linked to first name field in the Wix Members app collection.

As it will be only that site member who has access to that dynamic page, then it will simply just show the first name of that logged in user.

The database permissions are broken atm…