Moralis auth failed Moralis.Auth.requestMessage

I read this issue several times in this forum but somehow it didnt solved my issue. So here it is:

I used some boilerplate for nextjs and moralis. Im using the code from here:

Here is my request-message.js

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;

    await Moralis.start({ apiKey: process.env.MORALIS_API_KEY });

    try {
        const message = await Moralis.Auth.requestMessage({
            address,
            chain,
            network,
            ...config,
        });

        const messageJson = JSON.stringify(message); // Convert message to JSON string

        res.status(200).send(messageJson); // Send the JSON string in the response
    } catch (error) {
        const errorMessage = {
            message: error.message,
            stack: error.stack
        };
        
        res.status(400).json({ error: errorMessage });
        console.error(error);
    }
}

data:

{
  address: '0xC408356F8C8fa0Ee64833c983C214Ea8A84E1c2d',
  chain: 1,
  network: 'evm'
}
{
  domain: 'test',
  statement: 'Please sign this message to confirm your identity.',
  uri: 'http://localhost:3000',
  timeout: 60
}

The error is following:

error - TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'TLSSocket'
    |     property 'parser' -> object with constructor 'HTTPParser'
    --- property 'socket' closes the circle
    at JSON.stringify (<anonymous>)
    at sendJson (/Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/api-utils/node.js:197:19)
    at ServerResponse.apiRes.json (/Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/api-utils/node.js:360:31)
    at handler (webpack-internal:///(api)/./pages/api/auth/request-message.js:28:25)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.apiResolver (/Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/api-utils/node.js:372:9)
    at async DevServer.runApi (/Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/next-server.js:513:9)
    at async Object.fn (/Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/next-server.js:815:35)
    at async Router.execute (/Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/router.js:243:32)
    at async DevServer.runImpl (/Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/base-server.js:432:29)
    at async DevServer.run (/Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/dev/next-dev-server.js:814:20)
    at async DevServer.handleRequestImpl (/Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/base-server.js:375:20)
    at async /Users/****/Documents/Privat/cs-homepage/node_modules/next/dist/server/base-server.js:157:99 {
  page: '/api/auth/request-message'

which in detail is following…

MoralisError [Moralis SDK Core Error]: [C0006] Request failed with status undefined: timeout of 10000ms exceeded
    at RequestController.makeError (/Users/****/Documents/Privat/cs-homepage/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:137:20)
    at RequestController.<anonymous> (/Users/****/Documents/Privat/cs-homepage/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:118:38)
    at step (/Users/****/Documents/Privat/cs-homepage/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:44:23)
    at Object.throw (/Users/****/Documents/Privat/cs-homepage/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:25:53)
    at rejected (/Users/****/Documents/Privat/cs-homepage/node_modules/@moralisweb3/core/lib/controllers/RequestController.js:17:65)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  isMoralisError: true,
  code: 'C0006',
  details: {
    status: undefined,
    request: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 209,
      _requestBodyBuffers: [Array],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [ClientRequest],
      _currentUrl: 'https://auth-api.do-prod-1.moralis.io/challenge/request/evm',
      _timeout: null,
      [Symbol(kCapture)]: false
    },
    response: undefined
  }
}

The exact same code worked before. I did some changes to other pages of course … but didnt touched that code.

I hope someone can help me.

My API KEY is correct.
Im using localhost.

try to log the parameters used for request message

here try to add some logging to see if the parameters have the expected values

here is the data:

{
address: ‘0xC408356F8C8fa0Ee64833c983C214Ea8A84E1c2d’,
chain: 1,
network: ‘evm’
}

config
{
domain: ‘test’,
statement: ‘Please sign this message to confirm your identity.’,
uri: ‘http://localhost:3000’,
timeout: 60
}

I just downloaded the project fresh from https://github.com/IAmJaysWay/web3auth_database and I see the same issue.

what line generates that error?

this line generates the error:
const message = await Moralis.Auth.requestMessage({
address,
chain,
network,
…config,
});

and 5 days ago it was still working.

can you try it with hardcoded parameters?

Same error message using:

const message = await Moralis.Auth.requestMessage({
            address: '0xC408356F8C8fa0Ee64833c983C214Ea8A84E1c2d',
            chain: 1,
            network: 'evm',
            config: {
                domain: 'amazing.finance',
                statement: 'Please sign this message to confirm your identity.',
                uri: 'http://localhost:3000',
                timeout: 60,
            },
        });

that config, can you remove it and keep only data from it?

Thats it!!! Thank you so much.

No idea why this was working before. Did something changed on Moralis?

I don’t think that something changed regarding that syntax

just wondering because it worked before and in the git its exactly the same:

this syntax, maybe has different interpretations depending on other things?