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!