Bug with useMoralis react hook

Hi,

I am using react-moralis for authentication:

const { Moralis, account, isAuthenticated } = useMoralis();
const { chainId } = useChain();

  useEffect(() => {
    Moralis.enableWeb3();
  }, [Moralis]);

  useEffect(() => {
    if (!account || !chainId) return;

    //do some work
    dispatch(action)
  }, [account, chainId, dispatch]);

Is it normal that isAuthenticated=true whereas account=undefined?

Also, from my tests, account and chainId switch from defined to undefined multiple times, making my dispatched action triggered multiple times but it shouldn’t.

And sometimes I am getting the following error in the console:

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'on')
    at InternalWeb3Provider.<anonymous> (InternalWeb3Provider.js:134:1)
    at tryCatch (runtime.js:63:1)
    at Generator.invoke [as _invoke] (runtime.js:293:1)
    at Generator.next (runtime.js:118:1)
    at asyncGeneratorStep (asyncToGenerator.js:5:1)
    at _next (asyncToGenerator.js:27:1)

I don’t if I am doing something wrong here or if there is a real bug :frowning:

Thanks for your help!

I saw this error in another post today, maybe it is connected to latest version of Moralis SDK, Moralis JS-SDK v1.0.0 [beta] (Ethers.js support)

if you try with version 0.0.184 then it works fine?

i can try but the whole point for me was to upgrade to the last version. if you are saying that the last version is unstable so i will upgrade it later. I wanted to have support of etherjs.

then you can post in that thread specific to the latest version

ok sorry i thought it was not related

I don’t know if it is related, but it it works with the version before that update, then it could be related