I tried it, but same error. My request-message.js looks like this:
import Moralis from 'moralis';
const config = {
domain: process.env.APP_DOMAIN,
statement: 'Please sign this message to confirm your identity.',
uri: process.env.NEXTAUTH_URL,
timeout: 60,
};
export default async function handler(req, res) {
const { address, chain, network } = req.body;
if (!Moralis.Core.isStarted) {
await Moralis.start({ apiKey: process.env.MORALIS_API_KEY });
}
try {
const message = await Moralis.Auth.requestMessage({
address,
chain,
network,
...config,
});
res.status(200).json(message);
} catch (error) {
res.status(400).json({ error });
console.error(error);
}
}
My .env.local looks like this:
APP_DOMAIN=localhost
MORALIS_API_KEY=...
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=...
The full error looks like:
MoralisError [Moralis SDK Error]: [C0009] Modules are started already. This method should be called only one time.
at Core.<anonymous> (/Users/.../Documents/moralis-new/moralis-new/node_modules/@moralisweb3/common-core/lib/Core.js:94:35)
at step (/Users/.../Documents/moralis-new/moralis-new/node_modules/@moralisweb3/common-core/lib/Core.js:33:23)
at Object.next (/Users/.../Documents/moralis-new/moralis-new/node_modules/@moralisweb3/common-core/lib/Core.js:14:53)
at /Users/.../Documents/moralis-new/moralis-new/node_modules/@moralisweb3/common-core/lib/Core.js:8:71
at new Promise (<anonymous>)
at __awaiter (/Users/.../Documents/moralis-new/moralis-new/node_modules/@moralisweb3/common-core/lib/Core.js:4:12)
at Core.start (/Users/.../Documents/moralis-new/moralis-new/node_modules/@moralisweb3/common-core/lib/Core.js:88:57)
at Object.start (/Users/.../Documents/moralis-new/moralis-new/node_modules/moralis/lib/index.js:32:21)
at Object.authorize (webpack-internal:///(api)/./pages/api/auth/[...nextauth].js:35:74)
at Object.callback (/Users/.../Documents/moralis-new/moralis-new/node_modules/next-auth/core/routes/callback.js:360:29)
at AuthHandler (/Users/.../Documents/moralis-new/moralis-new/node_modules/next-auth/core/index.js:295:41)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async NextAuthHandler (/Users/.../Documents/moralis-new/moralis-new/node_modules/next-auth/next/index.js:23:19)
at async /Users/.../Documents/moralis-new/moralis-new/node_modules/next-auth/next/index.js:59:32
at async Object.apiResolver (/Users/.../Documents/moralis-new/moralis-new/node_modules/next/dist/server/api-utils/node.js:363:9)
at async DevServer.runApi (/Users/.../Documents/moralis-new/moralis-new/node_modules/next/dist/server/next-server.js:487:9)
at async Object.fn (/Users/.../Documents/moralis-new/moralis-new/node_modules/next/dist/server/next-server.js:749:37)
at async Router.execute (/Users/.../Documents/moralis-new/moralis-new/node_modules/next/dist/server/router.js:253:36)
at async DevServer.run (/Users/.../Documents/moralis-new/moralis-new/node_modules/next/dist/server/base-server.js:384:29)
at async DevServer.run (/Users/.../Documents/moralis-new/moralis-new/node_modules/next/dist/server/dev/next-dev-server.js:741:20)
at async DevServer.handleRequest (/Users/.../Documents/moralis-new/moralis-new/node_modules/next/dist/server/base-server.js:322:20) {
isMoralisError: true,
code: 'C0009',
details: undefined,
[cause]: undefined
}
Thank you for looking!