Hello, everyone, I wrote a code to sign in with rainbowkit by using useAuthRequestChallengeEvm(). But I have an urgent error!.
Code is the following!
import Head from "next/head";
// import Link from "next/link";
import { ConnectButton } from '@rainbow-me/rainbowkit';
import { useEffect } from "react";
import { useRouter } from "next/router";
import { signIn, useSession } from "next-auth/react";
import { useAccount, useSignMessage } from "wagmi";
// import { supabase } from "api";
import { useAuthRequestChallengeEvm } from '@moralisweb3/next';
export default function Home() {
const { isConnected, address, chainId } = useAccount();
const { status } = useSession();
const { signMessageAsync } = useSignMessage();
const { push } = useRouter();
const { requestChallengeAsync } = useAuthRequestChallengeEvm();
useEffect(() => {
console.log(isConnected)
const handleAuth = async () => {
console.log(address, chainId)
const response = await requestChallengeAsync({
address: address!,
chainId: chainId!,
});
if(response){
const message = response.message;
const signature = await signMessageAsync({ message });
// redirect user after success authentication to '/user' page
const signInResponse = await signIn("moralis-auth", {
message,
signature,
redirect: false,
callbackUrl: "/user",
});
/**
* instead of using signIn(..., redirect: "/user")
* we get the url from callback and push it to the router to avoid page refreshing
*/
const url = signInResponse?.url?.toString();
if (url) {
// push the URL to the router to avoid page refreshing
await push(url);
}
}
};
if (status === "unauthenticated" && isConnected) {
handleAuth().catch((error) => {
console.error("Authentication error:", error);
});
console.log("123")
}
}, [status, isConnected]);
return (
<>
<Head>
<title>Create T3 App</title>
<meta name="description" content="Generated by create-t3-app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className="flex min-h-screen bg-gradient-to-b justify-end from-[#2e026d] to-[#15162c] ">
<div className="m-2 fixed">
<ConnectButton />
</div>
</main>
</>
);
}
but in terminal find the error.
Moralis[nextjs]: Unknown error in MoralisNextApi: [C0006] Request failed: {
error: MoralisError [Moralis SDK Core Error]: [C0006] Request failed:
at RequestController.makeError (/home/william/Work/trial-test/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1235:16)
at RequestController.<anonymous> (/home/william/Work/trial-test/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1205:38)
at step (/home/william/Work/trial-test/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:83:23)
at Object.throw (/home/william/Work/trial-test/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:64:53)
at rejected (/home/william/Work/trial-test/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:55:65)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
isMoralisError: true,
code: 'C0006',
details: undefined,
[cause]: AxiosError [AggregateError]
at AxiosError.from (/home/william/Work/trial-test/node_modules/axios/dist/node/axios.cjs:837:14)
at RedirectableRequest.handleRequestError (/home/william/Work/trial-test/node_modules/axios/dist/node/axios.cjs:3087:25)
at RedirectableRequest.emit (node:events:531:35)
at eventHandlers.<computed> (/home/william/Work/trial-test/node_modules/follow-redirects/index.js:38:24)
at ClientRequest.emit (node:events:519:28)
at TLSSocket.socketErrorListener (node:_http_client:492:9)
at TLSSocket.emit (node:events:519:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
at Axios.request (/home/william/Work/trial-test/node_modules/axios/dist/node/axios.cjs:3877:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ETIMEDOUT',
errors: [Array],
config: [Object],
request: [Writable],
cause: [AggregateError]
}
}
}
please help me!