I uploaded a gif but it is not displayed, Let’s go in parts, first the login, then there is another error due to email authentication that in const user = await Moralis.User.current(); When I log in by email, the user does not recognize me, function login metamask
const Login = async () => {
setStateCircularProgress(true);
try {
const provider = "metamask";
await enableWeb3({ provider: provider});
console.log("account", account)
console.log("chainId", chainId)
const { message } = await Moralis.Cloud.run("requestMessage", {
address: account,
chain: parseInt(chainID.testNet),
network: "evm",
});
console.log("chainIdMoralis", message)
console.log("message", message)
console.log("chainId", chainId)
console.log("message", message)
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"
);
}
setValuesAlertFunc(true, "Login success", "success");
if (!state.authenticated) {
if (chainId != chainID.testNet ) {
await switchNetworkPolygon();
}
await Moralis.authenticate({
signingMessage: message,
}).then(async (user: any) => {
const userMarketType = user!.get("loginType");
setValuesAlertFunc(true, "Welcome to Koolinart", "success");
console.log('user', user)
dispatch({
type: "USER_AUTHENTICATED",
payload: true,
});
dispatch({
type: "GET_LOGIN_TYPE",
payload: userMarketType,
});
dispatch({
type: "USER_RENDER",
payload: user,
});
});
const ethAddress = state.userRender.attributes?.ethAddress
? state.userRender.attributes.ethAddress
: "";
await fetchTokenBalance(ethAddress);
}
} catch (e) {
const errorMessage = JSON.stringify(e);
const errorObjeto = JSON.parse(errorMessage);
setValuesAlertFunc(true, errorObjeto.message, "error");
console.log("error", e);
setStateCircularProgress(false);
}
};
I notice that the login works, reading the forum it worked, changing the import import Moralis from "moralis-v1";
to import { Moralis } from "moralis-v1";
but I have to give it 2 times to authenticate the first time it gives an error, why does this happen?, and i also notice that the string id is 80001, when i am in mumbai
const LoginMail = async (values: any) => {
setStateCircularProgress(true);
if (!state.authenticated) {
await Moralis.User.logIn(values.username, values.password )
.then(async function (user: any) {
const userMarketType = user.get("loginType");
dispatch({
type: "USER_AUTHENTICATED",
payload: true,
});
dispatch({
type: "GET_LOGIN_TYPE",
payload: userMarketType,
});
dispatch({
type: "USER_RENDER",
payload: user,
});
setValuesAlertFunc(true, "Welcome to Koolinart", "success");
})
.catch(function (error: any) {
// setValuesAlertFunc(true, " Invalid username/password.", "error");
const errorMessage = JSON.stringify(error);
const errorObjeto = JSON.parse(errorMessage);
setValuesAlertFunc(true, errorObjeto.message, "error");
setStateCircularProgress(false);
console.log("🚀 error de login", error);
});
const ethAddress = state.userRender.attributes?.ethAddress
? state.userRender.attributes.ethAddress
: "";
await fetchTokenBalance(ethAddress);
setStateCircularProgress(false);
}
};