[SOLVED] Uncaught TypeError: Cannot read properties of undefined (reading 'current')

Hello Guys

I’m trying to follow along with this video:

I’m stuck at the part where we try to refuse access to the Dashboard Website without logging in before hand. I keep getting this error:

Uncaught TypeError: Cannot read properties of undefined (reading 'current')
    at main.js:11
(anonymous) @ main.js:11

This is the code I’m trying to add:

     let homepage = "http://127.0.0.1:5500/index.html"
     if (Moralis.user.current() == null && window.location.href != homepage) {
      document.querySelector('body').style.display = 'none';
      window.location.href = "index.html";

I saw a similar issue on this forum from someone who forgot to add this line:

    <script src="https://unpkg.com/moralis/dist/moralis.js"></script>

But I have this on both index.html and on the dashboard.html

Only thing that is different from my code to the video is the part where we specify the moralis server, I used the newer code:

const serverUrl = "https://z78k3nmnabaz.usemoralis.com:2053/server";
const appId = "3KzncrAvIKMXnYii97IiyYb9TgoMHfy5GojZ7jyY";
 Moralis.start({ serverUrl, appId });

Is this the issue?

Thanks in advance for any help!

I think that it should be Moralis.User

omg thanks!! I can’t believe it was that easy of a fix :rofl:

Thanks a lot man!

1 Like