Hi,
I am trying to migrate my website from moralis hosted to self hosted. I have my moralis parse server running locally and have changed all my .env setting to reflect it.
I wrote out all of the code from the react docs and replaced the old connect wallet button with the one from this new code for the api auth.
However, when I click on the button absolutely nothing happens. There is no api request logged in the network logs, no logs from the server showing a requestMessage function was called, and no message sign request on the front end.
my console logs get to the āpassed the error checksā and thats itā¦
I have been using an older version of the moralis sdk, but installed moralis-v1 for this purpose.
my code was originally an exact copy of the example, but I have altered it a bit trying to debug.
here is my code for the auth after some attempts at correcting the issue:
import { useMoralis } from "react-moralis";
import Moralis from "moralis-v1";
import { useState } from "react";
import { useChain } from "react-moralis";
export const Connect = () => {
const { authenticate, enableWeb3, account } = useMoralis();
const [authError, setAuthError] = useState(null);
const [isAuthenticating, setIsAuthenticating] = useState(false);
const { chainId } = useChain();
async function handleAuth(provider) {
try {
setAuthError(null);
setIsAuthenticating(true);
console.log("starting auth");
await enableWeb3({ throwOnError: true, provider });
if (!account) {
console.log("account error");
throw new Error(
"Connecting to chain failed, as no connected account was found",
);
}
if (!chainId) {
console.log("chain error");
throw new Error("Connecting to chain failed, as no chain was found");
}
console.log("passed the error checks");
const { message } = await Moralis.Cloud.run("requestMessage", {
address: account,
chain: parseInt(chainId, 16),
network: "evm",
});
console.log("message set");
await authenticate({
signingMessage: message,
throwOnError: true,
});
console.log("things ran correctly");
} catch (error) {
setAuthError(error);
} finally {
setIsAuthenticating(false);
}
}
return (
<div>
<button onClick={() => handleAuth("metamask")}>
Connect with Metamask
</button>
</div>
);
};
EDIT:
I know that the front end is connected to the back end correctly because the getPluginSpecs function is being called