I would add this code
it works by adding this code but when i am connected to my metamask, it doesnโt show the logout and the profile button automatically, until i refresh the page then it will show, Please how can you help me to make it show automatically when i connected my wallet.
This is my new code below.
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("btn-login").style.display = "block";
document.getElementById("btn-logout").style.display = "none";
document.getElementById("btn-UserInfo").style.display = "none";
} else {
document.getElementById("btn-login").style.display = "none";
document.getElementById("btn-logout").style.display = "block";
document.getElementById("btn-UserInfo").style.display = "block";
}
}
hide_buttons();
async function login() {
let user = Moralis.User.current();
if (!user) {
user = await Moralis.authenticate({
signingMessage: "Welcome to GrandPaDoge NFT MarketPlace",
});
}
console.log("logged in user:", user);
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");
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;
document.getElementById("btn-userinfo").onclick = profile;
Take a look at the above code bro
it works by adding this code but when i am connected to my metamask, it doesnโt show the logout and the profile button automatically, until i refresh the page then it will show, Please how can you help me to make it show automatically when i connected my wallet.
you can add here
hide_buttons();
after that console.log("logged in user:", user);
line.
After adding this code, when i click on connect wallet, it will automatically show the logout button and the profile, but when i clicked on the logout button it wonโt show the connect button, please how can i do this?
You add same line that hides buttons at the end of logout function.
Okay i will do that now
It works perfectly now thank you. You guys need to open a trustpilot account so that we can give you guys a review. Moralis is a great platform to start your coding environment for free