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.
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
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"}}
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!
@ 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.