Ethereum-react-native-boilerplate and self-host server

when i connect to metamask and got this error
invalid data {“code”:101,“stack”:"Error: Moralis auth failed, invalid data

client  depence: {
    "react-moralis": "0.2.7",
    "moralis": "0.0.99",
}

Moralis-JS-SDK/demos/parse-server-migration servce error log
info: Ran cloud function getPluginSpecs for user undefined with:
  Input: {}
  Result: [] {"functionName":"getPluginSpecs","params":{}}
info: Ran cloud function getServerTime for user undefined with:
  Input: {}
  Result: null {"functionName":"getServerTime","params":{}}
error: Moralis auth failed, invalid data {"code":101,"stack":"Error: Moralis auth failed, invalid data\n    at /Moralis-JS-SDK/demos/parse-server-migration/src/auth/MoralisEthAdapter.ts:32:13\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n    at async Promise.all (index 0)"}


{
  id: '0xd1539c5e7033fd63edf3025b8e8bebc86db25fcf',
  signature: '0xb96f2430fa532ba635cfa795f967c0e9940a736b40469816ae54016d64075e852ff6627d9c0f293e3f068a1717a24a47d2eaea7bc9fd37c5ff54795857579a851b',
  data: 'Moralis Authentication'
} signaturesignaturesignature
{
  method: 'POST',
  name: 'verifyChallengeEvm',
  id: 'verifyChallengeEvm',
  groupName: 'evm',
  urlPathPattern: '/challenge/verify/evm',
  bodyParamNames: [ 'message', 'signature' ],
  bodyType: 'properties',
  getRequestUrlParams: [Function: getRequestUrlParams],
  getRequestBody: [Function: getRequestBody],
  serializeRequest: [Function: serializeRequest],
  deserializeRequest: [Function: deserializeRequest],
  deserializeResponse: [Function: deserializeResponse]
} https://authapi.moralis.io Core {
  modules: Modules {
    modules: Map(7) {
      'evmUtils' => [CommonEvmUtils],
      'solUtils' => [CommonSolUtils],
      'auth' => [Auth],
      'api' => [ApiUtils],
      'evmApi' => [EvmApi],
      'solApi' => [SolApi],
      'streams' => [Streams]
    }
  },
  config: Config {
    items: Map(9) {
      'logLevel' => [Object],
      'buidEnvironment' => [Object],
      'defaultNetwork' => [Object],
      'product' => [Object],
      'formatEvmAddress' => [Object],
      'formatEvmChainId' => [Object],
      'defaultSolNetwork' => [Object],
      'apiKey' => [Object],
      'defaultEvmApiChain' => [Object]
    }
  },
  logger: LoggerController {
    moduleName: 'core',
    config: Config { items: [Map] }
  },
  name: 'core',
  _isStarted: true,
  registerModules: [Function (anonymous)],
  registerModule: [Function (anonymous)],
  getModule: [Function (anonymous)],
  start: [Function (anonymous)]
}
 code: 'C0006',
  details: {
    status: 400,
    response: {
      status: 400,
      statusText: 'Bad Request',
      headers: [Object],
      config: [Object],
      request: [ClientRequest],
      data: [Object]
    }
  },
  [cause]: [AxiosError: Request failed with status code 400] {
    code: 'ERR_BAD_REQUEST',
    config: {
      transitional: [Object],
      adapter: [Function: httpAdapter],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 20000,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: Infinity,
      maxBodyLength: Infinity,
      env: [Object],
      validateStatus: [Function: validateStatus],
      headers: [Object],
      method: 'post',
      url: 'https://authapi.moralis.io/challenge/verify/evm',
      params: {},
      data: '{"message":"Moralis Authentication","signature":"0xb96f2430fa532ba635cfa795f967c0e9940a736b40469816ae54016d64075e852ff6627d9c0f293e3f068a1717a24a47d2eaea7bc9fd37c5ff54795857579a851b"}'
    },
    request: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'POST /challenge/verify/evm HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'x-moralis-platform: JS SDK\r\n' +
        'x-moralis-platform-version: 2.9.0\r\n' +
        'x-moralis-build-target: node\r\n' +
        'x-api-key: lZPCwr8rzvfKvQ6MNUVBsZq81GSeKe7Zb9YkIo0exahSYB2e2pTzQ27XasUtDhvm\r\n' +
        'User-Agent: axios/0.27.2\r\n' +
        'Content-Length: 183\r\n' +
        'Host: authapi.moralis.io\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/challenge/verify/evm',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'authapi.moralis.io',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    response: {
      status: 400,
      statusText: 'Bad Request',
      headers: [Object],
      config: [Object],
      request: [ClientRequest],
      data: [Object]
    }
  }
} eeeee

Can you show your authentication code?

And also try the latest react-moralis and moralis-v1 package versions.

The authentication logic using the react-moralis can also be found here.

error in server side , and react-moralis upgrade will make other problem

Moralis-JS-SDK/demos/parse-server

The message value which you are passing to the verify function should be message value which you received from the request message endpoint. Can you try changing that.

of course , so what params should send to cloud function

The link you mentioned above is about client code, but error in server side
Moralis-JS-SDK/demos/parse-server-migration

as you see server post
https://authapi.moralis.io/challenge/verify/evm with data data: '{"message":"Moralis Authentication","signature":"0xb96f2430fa532ba635cfa795f967c0e9940a736b40469816ae54016d64075e852ff6627d9c0f293e3f068a1717a24a47d2eaea7bc9fd37c5ff54795857579a851b"}'

// Note: do not import Parse dependency. see https://github.com/parse-community/parse-server/issues/6467
/* global Parse */
import Moralis from 'moralis';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function validateAuthData(authData: any) {
  const { signature, data } = authData;
  console.info(signature, 'signature, data ', data)

  return Moralis.Auth.verify({
    message: data,
    signature,
    networkType: 'evm',
  })
    .then((result) => {
      const authenticated = result.toJSON();

      authData.chainId = result.result.chain.decimal;
      authData.nonce = authenticated.nonce;
      authData.address = result.result.address.checksum;
      authData.version = authenticated.version;
      authData.domain = authenticated.domain;
      authData.expirationTime = authenticated.expirationTime;
      authData.notBefore = authenticated.notBefore;
      authData.resources = authenticated.resources;
      authData.statement = authenticated.statement;
      authData.uri = authenticated.uri;
      authData.moralisProfileId = authenticated.profileId;
    })

    .catch((e) => {
      console.info(e, 'eeeee')
      // @ts-ignore (see note at top of file)
      throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Moralis auth failed, invalid data');
    });
}

function validateAppId() {
  return Promise.resolve();
}

export default {
  validateAuthData,
  validateAppId,
};

It does not seem like an issue from the server side.

Can you try replacing the message value from Moralis Authentication with the actual message which you received from request-message endpoint.

We can’t pass a custom message to Moralis.Auth.verify function.

Moralis Authentication is the default code , i never change any critical code, just add some console.info(), so i really don’t know replace Moralis Authentication to what , actually Moralis Authentication is in this project initially

maby there are some error in react-moralis , the picture is capture from react-moralis github

Self-hosted parse server uses Auth API for authentication. There is a difference in how authentication is processed in the Moralis server vs the Self-hosted server. You can check this video to know more about auth API.

There will be a request message endpoint to request a challenge and a verify endpoint to verify the signature.

And this docs has the code on how to authenticate using self hosted server. using your client

// Get message to sign from the auth api
const { message } = await Moralis.Cloud.run('requestMessage', {
        address: account,
        chain: parseInt(chainId, 16),
        network: 'evm',
      });

      // Authenticate and login via parse
      await authenticate({
        signingMessage: message,
        throwOnError: true,
      });

thank you for you replying!
The Template is too old to use, i will set up a new one