I am unable to get userInfo and profile button not working - CLONE RARIBLE IN 24 HORS

I think that you didn’t properly upload the avatar yet, but you should be close

1 Like

It works now bro
I love you bro :kissing_smiling_eyes::kissing_heart::kiss::kissing_closed_eyes::grinning_face_with_smiling_eyes:
I love moralis, keep it up guys

1 Like

Is this proper or its also a problem to solve?
When i logout and refresh the page, and connect my wallet back, the avatar won’t display and also the username is not what i set which means the username as changed as well.


@cryptokid

Are you there bro ? @cryptokid

Looks strange, are you sure you authenticated with same address?
I would expect to see the profile that you set previously, and also same username

I tried to use another account, and its same thing, when i refresh the page and login again the username will change there won’t be any avatar showing @cryptokid

I mean, you don’t have to use another account, you should test with same account, but the profile data should remain there after you logout out and login again.

Its keeps changing bro, non of the data is saved why?

Look at my main.js file

const serverUrl = "https://mzrhanzmogsu.moralishost.com:2053/server";
const appId = "gFnTLmvgt8ZDUYMXF80FIonsCRqosKxXcfzmO2bM";
Moralis.start({ serverUrl, appId });

async function hide_buttons() {
    let user = await Moralis.User.current();
    if (!user) {
        document.getElementById("btnConnect").style.display = "block";
        document.getElementById("btnUserInfo").style.display = "none";
        document.getElementById("btnLogout").style.display = "none";
        document.getElementById("userInfo").style.display = "none";
    } else {
        document.getElementById("btnUserInfo").style.display = "block";
        document.getElementById("btnConnect").style.display = "none";
        document.getElementById("btnLogout").style.display = "block";
    }
}

hide_buttons();

async function login() {
    let user = Moralis.User.current();
    if (!user) {
        try {
            user = await Moralis.authenticate({
                signingMessage: "Welcome to GrandPaDoge NFT MarketPlace",
            });
        } catch (error) {
            alert(
                (error =
                    "Please consider installing Metamask to connect to MrGrandPaDoge NFT MarketPlace")
            );
        }
    }
    console.log("logged in user:", user);
    hide_buttons();
    const isWeb3Active = Moralis.ensureWeb3IsInstalled();

    if (isWeb3Active) {
        console.log("Activated");
    } else {
        async function enable() {
            await Moralis.enable();
        }
    }
}

async function logOut() {
    await Moralis.User.logOut();
    console.log("logged out");
    hide_buttons();
}

async function openuserInfo() {
    const user = Moralis.User.current();
    hide_buttons();
    if (user) {
        const email = user.get("email");
        if (email) {
            userEmailField.value = email;
        } else {
            userEmailField.value = "";
        }
        userUsernameField.value = user.get("username");
        const userAvatar = user.get("avatar");
        console.log(openuserInfo);

        if (userAvatar) {
            console.log(imgAvatar);
            console.log(userAvatar);
            imgAvatar.src = userAvatar.url();
            document.getElementById("imgAvatar").style.display = "block"; //display avatar
        } else {
            document.getElementById("imgAvatar").style.display = "none"; //hide avatar when user is connected
        }
        document.getElementById("userInfo").style.display = "block"; //Hide userinfo
    } else {
        login(); //if not,then login
    }
}

async function saveUserInfo() {
    let user = await Moralis.User.current();

    user.set("email", userEmailField.value);
    user.set("username", userUsernameField.value);

    if (fileAvatar.files.length > 0) {
        //get user avatar
        const avatar = new Moralis.File("avatar.jpg", fileAvatar.files[0]);
        console.log(fileAvatar.files);
        x = await avatar.save();
        console.log(x);
        user.set("avatar", x);
    }

    alert("User info saved successfully!");
    openuserInfo();
}

async function closeuserInfo() {
    user = await Moralis.User.current();
    hide_buttons();
    if (user) {
        document.getElementById("userInfo").style.display = "none";
        console.log("closed");
    } else {
        logOut();
    }
}

document.getElementById("btnConnect").onclick = login;
document.getElementById("btnLogout").onclick = logOut;
document.getElementById("btnUserInfo").onclick = openuserInfo;
document.getElementById("btnCloseUserInfo").onclick = closeuserInfo;
document.getElementById("btnSaveUserInfo").onclick = saveUserInfo;

const userUsernameField = document.getElementById("txtUsername");
const userEmailField = document.getElementById("txtEmail");
const userAvatarImg = document.getElementById("imgAvatar");
const userAvatarFile = document.getElementById("fileAvatar");

@cryptokid

what happens if you call this function in your browser console? like typing openuserInfo() and hitting enter?

This is what it show, but i tried to change the username but its not working if i logout and login again it won’t show the username i input to the username box


@cryptokid

only the username is the problem now?

Yes bro that’s the only problem

its been a while i see you online bro @cryptokid

I am online, you can try to debug it, to see what it displays as username there.

Bro how do i enable ipfs in my moralis server ?

its display a lot of characters as the username

IPFs is enabled by default

that is how a username looks initially, with random characters

Okay thanks bro i will look into it