Moralis self hosted server auth fails

Hi, I have deployed self hosted moralis server locally. Iā€™m getting error in function calls in endpoint like ā€œ/usersā€ after metamask login . I have also increased TIMEOUT and EXPIRATION_TIME at authService.ts. Stuck on how to debug further.

The error is given below -

{ 
code: 101
error: "Moralis auth failed, invalid data"
}

console.log(error) at MoralisEthAdapter.

MoralisError [Moralis SDK Core Error]: [C0006] Request failed, Bad Request(400): message must be present, message must contain only ASCII characters
    at RequestController.makeError (/Users/mars/Desktop/Workspace/parse-server-migration/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1206:20)
    at RequestController.<anonymous> (/Users/mars/Desktop/Workspace/parse-server-migration/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:1187:38)
    at step (/Users/mars/Desktop/Workspace/parse-server-migration/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:81:23)
    at Object.throw (/Users/mars/Desktop/Workspace/parse-server-migration/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:62:53)
    at rejected (/Users/mars/Desktop/Workspace/parse-server-migration/node_modules/@moralisweb3/common-core/lib/cjs/index.cjs:53:65)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  isMoralisError: true,
  code: 'C0006',

Hi, how does the message that you sign look like?

This is the payload of the request

{"authData":{"moralisEth":{"id":"0x3d2d631a38fbe88c8bb96ebc3ccde4fec263f2c6","signature":"0x4f609a3f39022dd332ee230ec4c098a3a4770f35ab8820bec0e3045fa9764aea41cd5038edb5da81ab45e623793a03f0e167dfecf1e4e48dfb69a28ba29bd8841b","data":"Hello World!\n\nId: QEnHypMEVBrVr8Z65QqYidPubNUV1WAdVa8wGPm8:1679337926786"}},"_ApplicationId":"QEnHypMEVBrVr8Z65QqYidPubNUV1WAdVa8wGPm8","_ClientVersion":"js0.0.118","_InstallationId":"ed0ab921-5560-467d-b4cb-765aec4c1f9a"}

this is a message specific to a managed moralis server and not to a self hosted server, you have to adapt the authentication for a self hosted server as in this tutorial:
https://v1docs.moralis.io/moralis-dapp/getting-started/self-hosting-moralis-server/client-connection#note-about-authentication

I have tried to run the react app snippent given but still got same response

Payload of react-moralis app version

{"authData":{"moralisEth":{"id":"0x3d2d631a38fbe88c8bb96ebc3ccde4fec263f2c6","signature":"0x78622e73b91bef219444923f852187c9158d8cea7d75f23e20aba28ccc94869d19b1f24b08f74a83494bdc5063f8e9c86a80132a8145260eefe5135241bc0e801b","data":"localhost wants you to sign in with your Ethereum account:\n0x3D2D631a38FBE88C8bb96EBc3cCdE4FEc263f2c6\n\nPlease sign this message to confirm your identity.\n\nURI: http://localhost:1337/server\nVersion: 1\nChain ID: 137\nNonce: oli1y9ArrvAjZ4oLU\nIssued At: 2023-03-21T05:36:10.330Z\nExpiration Time: 2023-03-21T08:06:09.116Z\nNot Before: 2023-03-21T05:36:09.116Z\n\nId: QEnHypMEVBrVr8Z65QqYidPubNUV1WAdVa8wGPm8:1679376970413"}},"_ApplicationId":"QEnHypMEVBrVr8Z65QqYidPubNUV1WAdVa8wGPm8","_ClientVersion":"js1.12.0","_InstallationId":"ed0ab921-5560-467d-b4cb-765aec4c1f9a"}

Payload of Moralis-JS-SDK-v1 version

{"authData":{"moralisEth":{"id":"0x3d2d631a38fbe88c8bb96ebc3ccde4fec263f2c6","signature":"0x10186ed02d9aae59a01d5b90fb78c8b6aeade04ec0bfcaccbf867ab3352d93407be3110ce5e5c2bc2f87054db3fa58378bbd510247f2ddf23506fedc3d5c1e601c","data":"localhost wants you to sign in with your Ethereum account:\n0x3D2D631a38FBE88C8bb96EBc3cCdE4FEc263f2c6\n\nPlease sign this message to confirm your identity.\n\nURI: http://localhost:1337/server\nVersion: 1\nChain ID: 137\nNonce: aW8cVMjQwGVAtAcsT\nIssued At: 2023-03-21T05:34:34.719Z\nExpiration Time: 2023-03-21T08:04:34.087Z\nNot Before: 2023-03-21T05:34:34.087Z\n\nId: QEnHypMEVBrVr8Z65QqYidPubNUV1WAdVa8wGPm8:1679376874747"}},"_ApplicationId":"QEnHypMEVBrVr8Z65QqYidPubNUV1WAdVa8wGPm8","_ClientVersion":"js1.12.0","_InstallationId":"cbe42d0d-e1e6-409f-b21c-b6b392660761"}

what issues are you having now, this looks like the expected format for the message

Getting same issue. If I connect to self hosted moralis server.

this is the error that you get now?

Yes. Iā€™m getting same error.

{ 
code: 101
error: "Moralis auth failed, invalid data"
}

the message has this part at the, end, make sure that you didnā€™t modify the cloud function for getServerTime, that part from the end with app id and a timestamp should not be present in the message to sign

Attached the current getServerTime function, which is modified to return similar response as the server one.

You donā€™t have to modify that function. If you modify it then the authentication will stop working.

Hey @cryptokid, I am facing the same issue of invalid auth. I am running the code given for migrating for both backend and frontend.

My getServerTime function is also untouched.

Parse.Cloud.define('getServerTime', () => {
  // Not implemented, only excists to remove client-side errors when using the moralis-v1 package
  return null;
});
 

If you can please help with it.

It looks like it displays the message, where is the issue?

The same issue of

 { 
code: 101
error: "Moralis auth failed, invalid data"
}

This message also shows up recently, before this wasnā€™t the case. The authentication was working fine with self hosted DB.

As you mentioned above that getServerTime function shouldnā€™t be modified and due that this error is occurring. But for me I havenā€™t changed that function, still the same issue.

Can you paste the compete message that you get to sign?

sure, sign message

localhost wants you to sign in with your Ethereum account:
0xFb9d48dE97769E15181a06E37820072D1A5348A0

Please sign this message to confirm your identity.

URI: http://localhost:3002/server
Version: 1
Chain ID: 43113
Nonce: nFCuZ5iGiBKmNAH3Z
Issued At: 2023-03-23T12:53:23.614Z
Expiration Time: 2023-03-23T13:08:22.632Z
Not Before: 2023-03-23T12:53:22.632Z 

I donā€™t see anything strange in this message

Respected @cryptokid, Please understand my issue.

Issue: I am not able to authenticate, on authenticating, I am getting

 { 
code: 101
error: "Moralis auth failed, invalid data"
}

Also, before when the metamask opens up, I donā€™t see the unsafe message, but now I am getting that also. So anything has changed from Moralis side?

As you were suggesting to @mars that this could be issue of changing getServerTime function, but in my case the function is as it is.

Now can you please give the insight?

image

Also if you can please help me decoding how to resolve

"Deceptive site request" message in Metamask, it means that the website you are trying to access through Metamask is not matching the domain for which you granted permission to access your Metamask account

As it wasnā€™t the case with moralis server, and also the self hosted in that matter, but for couple of days I am getting this warning on metamask.