I have been stuck at this problem for while. Please help me. Please look at the code and screenshot below.
index.html
<!DOCTYPE html>
<html>
<head>
<title>Vanilla Boilerplate</title>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
</head>
<body>
<h1>Moralis Hello World!</h1>
<button id="btn-login">Moralis Metamask Login</button>
<button id="btn-logout">Logout</button>
<script type="text/javascript" src="./main.js"></script>
</body>
</html>
main.js
/* Moralis init code */
const serverUrl = "https://crixzoshpewy.usemoralis.com:2053/server";
const appId = "YKxHpYcmCSmieEL6vUl4C4vvdI9su0aSMciz6NmBg";
Moralis.start({ serverUrl, appId });
/* TODO: Add Moralis Authentication code */
async function login() {
let user = Moralis.User.current();
if (!user) {
user = await Moralis.authenticate({
signingMessage: "Log in using Moralis",
})
.then(function (user) {
console.log("logged in user:", user);
console.log(user.get("ethAddress"));
})
.catch(function (error) {
console.log(error);
});
}
}
async function logOut() {
await Moralis.User.logOut();
console.log("logged out");
}
document.getElementById("btn-login").onclick = login;
document.getElementById("btn-logout").onclick = logOut;
I used same code given in the below link
https://docs.moralis.io/moralis-dapp/connect-the-sdk/connect-with-js