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: