Very strange behaviour ! I cant point out the issue yet, but the problem is when we first land on the page we can authenticate with metamask using the authenticate()
of useMoralis()
hook. Once we authenticate we can use the constant account
variable from the useMoralis()
hook.
But once we reload the page, it again needs to authenticate and we can not use our account variable now. Neither we can call our useWeb3Contract()
hook.
I still cant figure out the way around. Please look in. Any help is appreciated.
Try using isAuthenticated
or user
from useMoralis to check for user authentication. You can also get the user address from user
const { isAuthenticated, user } = useMoralis();
The thing is user is saved into the localstorage every time we authenticate()
. Moralis would always get the user from there even when we are not authenticated.
did you use useEffect after page reloads?
Yes, Iβm using UseEffect for every page reload!
How are you testing this?
In case, if you are manually disconnecting from metamask or deleting the localstorage, it wonβt update the data stored in the user variable.