Question:
Why does this code not return the value in the Nickname data?
Product:
WIX custom code
What are you trying to achieve:
I have a textbox in the Header named “Logname”. When a person logs in, I want the header to display the Wix-FullData-Nickname value. It keeps returning “null”.
What have you already tried:
import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import { local } from ‘wix-storage-frontend’;
$w.onReady(function () {
const user = wixUsers.currentUser;
const loggedIn = user.loggedIn;
if (loggedIn) {
wixData.query("Members/FullData")
.find()
.then((results) => {
if (results.items[0].nickname === null) {
// On first page set a Local Data item for their Nickname
local.setItem("Logname", results.items[0].nickname);
local.setItem("JungleXP", 0);
} else {
local.setItem("Logname", "Adventurer");
local.setItem("JungleXP", " ");
}
// Now display it in the header
// $w('#namebox').text = "Welcome " + local.getItem("Logname") + "??";
$w('#namebox').text = "Welcome " + local.getItem("Logname");
$w('#XPbox').text = "XP: " + local.getItem("JungleXP");
})
} else {
$w('#namebox').text = "Please Log In.";
$w('#XPbox').text = " ";
$w("#btnJungleStart").disable()
.then(() => {
$w("#btnJungleStart").label = "Locked - Log In";
});
}
});