Hi, Iām using this code for the user login:
import { useMoralis } from 'react-moralis';
import { useEffect, useState } from "react";
import Moralis from 'moralis-v1';
// import metamask from '/images/metamask.png';
export const LoginComponent = ({ closeModal }) => {
const { isAuthenticated, authenticate, enableWeb3, account, chainId } = useMoralis();
const [authError, setAuthError] = useState(null);
const [isAuthenticating, setIsAuthenticating] = useState(false);
const handleAuth = async (provider) => {
try {
await Moralis.start({
apiKey: process.env.NEXT_PUBLIC_MORALIS_API_KEY,
serverUrl: process.env.NEXT_PUBLIC_MORALIS_SERVER_URL,
appId: process.env.NEXT_PUBLIC_MORALIS_APP_ID
});
setAuthError(null);
setIsAuthenticating(true);
// Enable web3 to get user address and chain
await enableWeb3({ throwOnError: true, provider });
// console.log(account, chainId, provider)
if (!account) {
throw new Error('Connecting to chain failed, as no connected account was found');
}
if (!chainId) {
throw new Error('Connecting to chain failed, as no connected chain was found');
}
// Get message to sign from the auth api
const { message } = await Moralis.Cloud.run('requestMessage', {
address: account,
chain: chainId,
network: 'evm',
});
// Authenticate and login via parse
await authenticate({
signingMessage: message,
provider: provider,
chainId: chainId,
throwOnError: true,
});
} catch (error) {
console.log(error)
setAuthError(error);
} finally {
setIsAuthenticating(false);
}
};
const buttonStyle =
"bg-black backdrop-filter animate-fade-in-up py-2 px-6 mt-4 text-white text-base font-bold rounded-2xl border-black border-2 border-b-8 transform duration-300 hover:scale-1002 hover:shadow-bluxl";
useEffect(() => {
if (isAuthenticated) {
closeModal()
}
}, [closeModal, isAuthenticated])
return (
<div className='w-full text-center py-12 grid px-8'>
<button className={buttonStyle}
onClick={() => {
handleAuth("metamask");
}}>
{/* <metamask className='w-6 h-6 inline-block mr-2' /> */}
Metamask
</button>
<button className={buttonStyle} onClick={() => handleAuth("walletconnect")}>
Walletconnect</button>
<div className='pt-6 text-center text-xs animate-pulse font-bold'>{isAuthenticating ? "Authenticating..." : ""}</div>
</div>
)
}
walletconnect is not working, both on desktop browser and mobile, the console errors are the following:
POST https://speedy-nodes-nyc.moralis.io/WalletConnect/polygon/mumbai net::ERR_FAILED
Error: PollingBlockTracker - encountered an error while attempting to update latest block:
undefined
Any suggestion on how we could fix this?