Found a Bug! Need Urgent Pro Help

Hello!
I used this code to get loggedin users name this code worked before but for some reason it stopped working today on both of my sites i need urgent help! i might even lose my job!
here is the code

let user = wixUsers.currentUser;
if (wixUsers.currentUser.loggedIn) {
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
.find()
.then((results) => {
$w("#CurrentUser").text = results.items[0].name;

})
}

Thanks

Just look in the Wix Users API as there is already a sample code there for getting last name, just change it to first name
https://www.wix.com/corvid/reference/wix-users.User.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; \
  } );

Thanks for replay ill try it now

Used your code it didnt work i still cant get Last name or Full name

Just checked my end as well and it looks like it has bugged for some reason.

It will be reported, thanks for letting us know.

Thanks for posting so that it could be looked into. :+1:

Thanks to you for taking it serious :slight_smile: i hope it gets fixed soon.

@xpuehsan In the meantime try retrieving the name using a backend function. Create a .jsw file on your site, name the file userName and use the following code on it.

//userName.jsw

import wixData from 'wix-data';

let options = {
    "suppressAuth": true
};

export function getName(userId) {
    return wixData.query("Members/PrivateMembersData")
    .eq("_id", userId)
    .find(options)
    .then( (results) => {
        let name = results.items[0].name;
        return name;
    });
}

Call the function from your page like shown below.

import {getName} from 'backend/userName.jsw';
import wixUsers from 'wix-users';

$w.onReady(function () {
    let user = wixUsers.currentUser;
    if (wixUsers.currentUser.loggedIn) {
        let userId = wixUsers.currentUser.id;
        getName(userId)
        .then( (name) => {
            $w("#CurrentUser").text = String(name);
        });
    }
});

@shantanukumar847 Thanks Bro!