Hi,
Checking the user object can help you or instead of using await
, you could use .then
in your Moralis authenticate calls.
I tried a simple implementation to give you a direction -
Moralis.start({ serverUrl, appId });
const btnlogin = document.getElementById("btn-login");
let user = Moralis.User.current();
if (!user) {
btnlogin.style.display = "block";
} else {
btnlogin.style.display = "none";
}
async function login() {
if (!user) {
user = await Moralis.authenticate({
signingMessage: "Welcome to GrandPaDoge",
});
if (user) {
btnlogin.style.display = "none";
}
}
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();
btnlogin.style.display = "block";
console.log("logged out");
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;