Cannot read properties of null (reading 'authenticate')

Good day everyone, I was going through a tutorial on NFTs and I was in the process of creating a NFT dashboard. The dashboard had a login function and I was in the process of creating that when I ran into the following error message:

TypeError: Cannot read properties of null (reading 'authenticate')
    at initializeApp (main.js:8:46)
    at main.js:17:1

The main.js is shown below:

Moralis.initialize("OZVYMombz6VvGYRGnthVIFeGGQFGQHvFpBGWr2rO");

Moralis.serverURL = "https://8uvfmvqjccfn.usemoralis.com:2053/server";

async function initializeApp(){

    try{

        let currentUser = Moralis.User.current();

        if(!currentUser){

            currentUser = await Moralis.web3.authenticate();

        }

        alert("user is signed in!");

    } catch (error) {

        console.log(error);

    }

}

initializeApp();

I believe you are using a very old way of initializing Moralis :sweat_smile:

Use Moralis.start({appId: <yourAppIdHere>, serverUrl: <yourServerUrlHere>})

Thanks a lot Kone, it worked

1 Like