Hello, the authentication was working. and now it gives me an error, update moralis, and it stopped working. It was working normally with metamask, the authentication left the front and server code.
error:
error: Failed running cloud function requestMessage for user undefined with:
Input: {"address":"0x0bf75e9e3251fda1a66bd449c8630f16a2c3cabe","chain":80001,"network":"evm"}
Error: {"message":"[C0006] Request failed, Bad Request(400): Unauthorized","code":141} {"error":{"code":141,"message":"[C0006] Request failed, Bad Request(400): Unauthorized"},"functionName":"requestMessage","params":{"address":"0x0bf75e9e3251fda1a66bd449c8630f16a2c3cabe","chain":80001,"network":"evm"}}
error: [C0006] Request failed, Bad Request(400): Unauthorized {"code":141,"stack":"Moralis SDK Core Error: [C0006] Request failed, Bad Request(400): Unauthorized\n at RequestController.makeError (C:\\Users\\david\\Documents\\Programacion\\react\\Koolinart\\backend\\node_modules\\@moralisweb3\\common-core\\lib\\cjs\\index.cjs:1224:20)\n at RequestController.<anonymous> (C:\\Users\\david\\Documents\\Programacion\\react\\Koolinart\\backend\\node_modules\\@moralisweb3\\common-core\\lib\\cjs\\index.cjs:1205:38)\n at step (C:\\Users\\david\\Documents\\Programacion\\react\\Koolinart\\backend\\node_modules\\@moralisweb3\\common-core\\lib\\cjs\\index.cjs:83:23)\n at Object.throw (C:\\Users\\david\\Documents\\Programacion\\react\\Koolinart\\backend\\node_modules\\@moralisweb3\\common-core\\lib\\cjs\\index.cjs:64:53)\n at rejected (C:\\Users\\david\\Documents\\Programacion\\react\\Koolinart\\backend\\node_modules\\@moralisweb3\\common-core\\lib\\cjs\\index.cjs:55:65)\n at processTicksAndRejections (node:internal/process/task_queues:96:5)"}
function login:
const Login = async () => {
setStateCircularProgress(true);
try {
const provider = "metamask";
await enableWeb3({ provider: provider });
const { account, chainId } = Moralis;
const { message } = await Moralis.Cloud.run("requestMessage", {
address: account,
chain: parseInt(chainID.testNet),
network: "evm",
});
console.log("account", account);
console.log("chainId", chainId);
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"
);
}
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);
const ethAddres = user!.get("ethAddress");
dispatch({
type: "USER_RENDER",
payload: user,
});
dispatch({
type: "USER_AUTHENTICATED",
payload: true,
});
dispatch({
type: "GET_LOGIN_TYPE",
payload: userMarketType,
});
await fetchTokenBalance(ethAddres);
});
}
setValuesAlertFunc(true, "Login success", "success");
setStateCircularProgress(false);
} catch (e) {
const errorMessage = JSON.stringify(e);
const errorObjeto = JSON.parse(errorMessage);
setValuesAlertFunc(true, errorObjeto.message, "error");
console.log("error", e);
setStateCircularProgress(false);
}
};
The auth code is the same as Moralis in the repo at https://github.com/MoralisWeb3/Moralis-JS-SDK/tree/main/demos/parse-server-migration