Hi all, Im trying to work the βI BUILT AN NFT GAME (Part 3)β by Philip, but his mod to the boilerplate does not seem to work. If goes directly into the rendergame function without checking the try or the click function. After I log out (part of rendergame function), the login button appears but when I click it, metamask does not respond
Could you share the error message from the console?
Sorry I copied the incorrect code, Please see the below gist
It does not allow for the if clause (button click) to run. Upon re-run the there is no effect to the clicking of the button. I believe when Philip wrote the code, he did not check if it works for user=null as he was already signed in. So basically whether a user is signed in or not, rendergame() runs which should not be the case. The function rendergame should only run after the user has logged in.
My question is how to correct it such that rendergame only runs if the user is logged in
If(user=null) may not do what you expect.
It was (!user), same issue
Currently Moralis.Web3.authenticate()
doesnβt support .then
. So, you need to use this method:
async function init() {
let user = Moralis.User.current();
console.log(user);
if (user) {
renderGame();
} else {
$("#login_button").click(async () => {
try {
user = await Moralis.Web3.authenticate();
renderGame();
console.log(user);
} catch (error) {
console.log(error);
}
});
}
}
Perfect. Thank you. resolved