Error when logging in as non-crypto user using react-moralis

I have been following the twitter clone tutorial on youtube using react-moralis.

However, if I log in as a non-crypto user, I get the following error:

I’ve tried both methods of using “get” and the “user.attributes.username” as shown in the video. Both get me the same error.

The strange thing is, when I refresh the page, everything works normally. It’s like it’s taking me to the authenticated page without finalising authentication. I assume I need to “await” authentication or something but the youtube tutorial doesn’t show this and it works perfectly on the tutorial. Have I missed something?

Hey @hughesy

Most likely the point is that the user object apparently does not have enough time to load.

The code bellow will call user’s attributes only if object user is defined.

{ user ? user.attributes.username} 

You can make a global require that check for the presence of a user object is performed before the page is rendered.

1 Like

Hi @Yomoo thanks for the quick reply. Your suggestion worked although I used {user?.attributes.username} as your suggestion was giving me unexpected token for some reason.

Thanks again!

Yes, it’s better to use {user?.attributes.username}

Happy BUIDLing :man_mechanic: