I am only at episode 2 of the Youtube tutorial, and already many problems happening. Unsure why the âinitUserâ works one way, but not another. Then when I click on âProfileâ later on, nothing displays.
Here is the JS code:
âââ
Moralis.initialize(â3IcvId63X3g2jWHA2t2OCOFDHmfOw3PbF9etB6Mtâ);
Moralis.serverURL = âhttps://k8lq9f7lkimp.moralis.io:2053/serverâ
init = async () => {
hideElement(userInfo);
window.web3 = await Morialis.web3.enable();
initUser();
}
initUser = async () => {
if (await Moralis.User.current()){
hideElement(userConnectButton);
showElement(userProfileButton);
}else{
showElement(userConnectButton);
hideElement(userProfileButton);
}
}
login = async () => {
try {
await Moralis.Web3.authenticate();
initUser();
} catch (error) {
alert(error)
}
}
logout = async () => {
await Moralis.user.logOut();
hideElement(userInfo);
initUser();
}
OpenUserInfo = async() =>{
user = await Moralis.user.current();
if (user){
showElement(userInfo)
}else{
login();
}
}
hideElement = (element) => element.style.display = ânoneâ;
showElement = (element) => element.style.display = âblockâ;
const userConnectButton = document.getElementById(âbtnConnectâ);
userConnectButton.onclick = login;
const userProfileButton = document.getElementById(âbtnUserInfoâ);
userProfileButton.onclick = OpenUserInfo;
const userInfo = document.getElementById(âuserInfoâ);
document.getElementById(âbtnCloseUserInfoâ).onclick = () => hideElement(userInfo);
document.getElementById(âbtnLogoutâ).onclick = logout;
init();
âââ
Here is the HTML code:
âââ
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Latin Ark</title>
<div>
<button id='btnConnect'>Connect Wallet</button>
<button id='btnUserInfo'>Profile</button>
</div>
<div id='userInfo'>
<h4>User Profile</h4>
<input type='text' id='txtUsername' required placeholder="Enter Username">
<input type='text' id='txtEmail' placeholder="Enter Email">
<small>Optional</small>
<img src="" alt="" id="imgAvatar">
<label for='fileAvatar'>Select your avatar</label>
<input type='file' id='fileAvatar'>
<button id='btnLogout'>Log Out</button>
<button id='btnCloseUserInfo'>Close</button>
<button id='btnSaveUserInfo'>Save</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
<script src="main.js"></script>
'''
Do I need to install a package or something in order to make this work? Any/all help is appreciated!